My data source for the charts is a collection of objects, I have set up the data mapping and called databind to setup the data points.
On 'clicking' a data point I need access to the data source the item is bound to and as far as I can tell this isnt possible. Is it possible to attatch a reference to the underlying object in each datapoint?
There is an event on the chart called DataItemMouseLeftButtonDown which should help you here. The method to obtain the source item varies a bit per chart, you can see this post and its replies for some variants: https://ko.infragistics.com/community/forums/f/retired-products-and-controls/36069/how-to-get-the-datapoint-value-in-line-splinearea-doughnut-charts
If you can tell me wchich chart type you are dealing with I can provide you some further advice.
-Graham
Thanks for the fast response. This allows me to get the data point I am bound to, but how do I obtain the object that produced this binding? Its very straight forward to do this using the control toolkit charts. Heres how I am binding the series (on clicking a node I need to get my cell object so I can use the meta data to build a drill down query):
s.DataSource = dataSource.RowCellCollection as IEnumerable; s.Label = dataSource.SeriesItem.Caption; /* Setup the bindings configured in the attached properties */ s.DataMapping = String.Format("Value={0};Label={1};", DependentValueBinding, "Caption"); // noticed that binding can't deal with x.y properties so had to add property to rowcell class to access cell meta data s.DataBind();
Again, your strategy will have to vary a bit depending on your chart type, but how does this work for you?
private void theChart_DataItemMouseLeftButtonDown( object sender, DataItemMouseEventArgs e) { DataPointTemplate template = e.Element as DataPointTemplate; if (template != null) { DataPoint point = template.DataPoint; ObservableCollection<TestSampleData> dataSource = template.Series.DataSource as ObservableCollection<TestSampleData>; int index = template.Series.DataPoints.IndexOf(point); if (index >= 0 && dataSource != null) { MessageBox.Show(dataSource[index].Label); } } }
Thanks for getting back to me so soon, that works fine.