The app it's designed to present multiple sales charts into a rotator dynamically, for example some charts need to enable zooming but some others don't.
I have a model from my charts, every chart are into a SfRotator and i want to control the behaviors for each chart so the model contains a Behaviors(ChartBehaviorCollection) property:
Here's the rotator item model:
public class RotatorModel: INotifyPropertyChanged
{
//Some full properties
private ChartBehaviorCollection _chartBehavior;
public ChartBehaviorCollection Behaviors
{
get
{
return _chartBehavior;
}
set
{
if (_chartBehavior != value)
{
_chartBehavior = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Behaviors)));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Here's the code where i'm trying to add the behaviors for each model:
private ObservableCollection<RotatorModel> _rotatorElements;
public ObservableCollection<RotatorModel> RotatorElements
{
get
{
return _rotatorElements;
}
set
{
if (_rotatorElements != value)
{
_rotatorElements = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RotatorElements)));
}
}
}
public async Task LoadSales()
{
RotatorElements = new ObservableCollection<RotatorModel>();
//some code to get the data
foreach (var graph in graphData.Graphs)
{
SfChart chart = new SfChart();
chart.Title = new ChartTitle() { Text = graph.GraphLabel };
//Chart behaviors
ChartZoomPanBehavior chartZoomPanBehavior = new ChartZoomPanBehavior();
chartZoomPanBehavior.EnableZooming = true;
chartZoomPanBehavior.EnableDoubleTap = true;
ChartTooltipBehavior chartTooltipBehavior = new ChartTooltipBehavior();
chartTooltipBehavior.BackgroundColor = Color.Red;
chartTooltipBehavior.BorderWidth = 1;
chartTooltipBehavior.BorderColor = Color.Black;
chartTooltipBehavior.TextColor = Color.White;
chartTooltipBehavior.Duration = 2;
chart.ChartBehaviors.Add(chartTooltipBehavior);
chart.ChartBehaviors.Add(chartZoomPanBehavior);
//some code
RotatorModel model = new RotatorModel();
model.Series = chart.Series;
model.Title = chart.Title;
model.PrimaryAxis = primaryAxis;
model.SecondaryAxis = secondaryAxis;
model.Behaviors = chart.ChartBehaviors;
RotatorElements.Add(model);
}
}
and here's the xaml:
<syncfusion1:SfRotator
EnableLooping="False"
EnableSwiping="True"
ItemsSource="{Binding RotatorElements}"
NavigationDirection="Horizontal"
NavigationStripMode="Dots"
NavigationStripPosition="Bottom">
<syncfusion1:SfRotator.ItemTemplate>
<DataTemplate>
<chart:SfChart
ChartBehaviors="{Binding Behaviors}"
Series="{Binding Series}"
Title="{Binding Title}"
PrimaryAxis="{Binding PrimaryAxis}"
SecondaryAxis="{Binding SecondaryAxis}">
<chart:SfChart.ColorModel>
<chart:ChartColorModel
Palette="Custom"
CustomBrushes="{StaticResource Colors1}"/>
</chart:SfChart.ColorModel>
</chart:SfChart>
</DataTemplate>
</syncfusion1:SfRotator.ItemTemplate>
</syncfusion1:SfRotator>