I've got a 'dashboard' with several charts on it. One of them is a pie chart with a number of series.
LiveCharts has a DataClick event
DataClick(object sender, ChartPoint chartPoint)
sender is of type PieSlice. How can i access SeriesCollection from that event or, alternatively, chart name / id?
What I am trying to achieve is access chart that sent the event, then it's series collection and check which of the series / pie slice fired the event.
First and foremost, don't use events, use commands - that's the MVVM way. i.e.
<LiveCharts:PieChart DataClickCommand="{Binding DrillDownCommand}" Series="{Binding MySeries}" ...>
Note the binding to MySeries:
public SeriesCollection MySeries
{
get
{
var seriesCollection = new SeriesCollection(mapper);
seriesCollection.Add(new PieSeries()
{
Title = "My display name",
Values = new ChartValues<YourObjectHere>(new[] { anInstanceOfYourObjectHere })
});
return seriesCollection;
}
}
And about handling the command:
public ICommand DrillDownCommand
{
get
{
return new RelayCommand<ChartPoint>(this.OnDrillDownCommand);
}
}
private void OnDrillDownCommand(ChartPoint chartPoint)
{
// access the chartPoint.Instance (Cast it to YourObjectHere and access its properties)
}
You need to work with arguments, not the sender. The second parameter is ChartPoint, that cointains SeriesView. So just access it and use it's Title:
private void Chart_OnDataClick(object sender, ChartPoint chartpoint) {
MessageBox.Show(chartpoint.SeriesView.Title);
}
How can i access SeriesCollection from that event or, alternatively, chart name / id?
SeriesView is not the whole SeriesCollection, but Series you clicked on. And you can have it's name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With