Reputation: 233
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.
Upvotes: 3
Views: 3647
Reputation: 4130
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)
}
Upvotes: 6
Reputation: 3885
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
Upvotes: 2