Hi guys,
I'm using Syncfusion Xamarin SfChart to display a Doughnut Chart in one of my projects. I have a items list and a chart. When I select an item from list I set SelectedDataPointIndex of chart through a property in viewmodel, all works fine. But when I touch a chart fragment nothing happens in my viewmodel, it doesn't detect the new index.
I'm using Syncfusion.SfChart.XForms version 14.2451.0.32.
Here is my code:
------------------------------------------------------------------------------------------
<chart:SfChart BackgroundColor="White" HeightRequest="200">
<chart:SfChart.Title>
<chart:ChartTitle Text="Doughnut Chart" TextColor="White"/>
</chart:SfChart.Title>
<chart:SfChart.Series>
<chart:DoughnutSeries ItemsSource="{Binding Accounts}"
XBindingPath="Description"
YBindingPath="Amount"
ExplodeOnTouch="False"
EnableAnimation="True"
StrokeWidth="2"
StrokeColor="White"
DoughnutCoefficient="0.75"
EnableDataPointSelection="True"
SelectedDataPointColor="#1094F6"
SelectedDataPointIndex="{Binding Chart_SelectionIndex}">
<chart:DoughnutSeries.ColorModel>
<chart:ChartColorModel Palette="Custom" CustomBrushes="{Binding Colors}"/>
</chart:DoughnutSeries.ColorModel>
</chart:DoughnutSeries>
</chart:SfChart.Series>
</chart:SfChart>
<ListView ItemsSource="{Binding Accounts}" HeightRequest="200" SelectedItem="{Binding List_SelectedItem}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="5,5">
<Label Text="{Binding Description}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
------------------------------------------------------------------------------------------
public class DoughnutViewModel : INotifyPropertyChanged
{
#region Chart
private int Chart_selectionIndex;
public int Chart_SelectionIndex
{
get
{
return Chart_selectionIndex;
}
set
{
Chart_selectionIndex = value;
OnPropertyChanged();
}
}
#endregion
#region List
private Account List_selectedItem;
public Account List_SelectedItem
{
get
{
return List_selectedItem;
}
set
{
List_selectedItem = value;
var index = Accounts.IndexOf(value);
Chart_SelectionIndex = index;
OnPropertyChanged();
}
}
#endregion
#region Property Changed
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string property = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
#endregion
public ObservableCollection<Account> Accounts { get; set; }
public List<Color> Colors { get; set; }
public DoughnutViewModel()
{
Accounts = new ObservableCollection<Account>();
Accounts.Add(new Account { Description = "Checking 1", Amount = 1000 });
Accounts.Add(new Account { Description = "Checking 2", Amount = 2000 });
Accounts.Add(new Account { Description = "Checking 3", Amount = 3000 });
Accounts.Add(new Account { Description = "Checking 5", Amount = 5000 });
Accounts.Add(new Account { Description = "Checking 8", Amount = 8000 });
Accounts.Add(new Account { Description = "Checking 13", Amount = 13000 });
Colors = new List<Color>();
Colors.Add(Color.FromHex("#D2D4D7"));
}
}
------------------------------------------------------------------------------------------
What could it be?
Thanks in advance,