Hi,
I have a column chart. When I click on a column in the chart, I want that the selected column chart shows a selected style and I know which column is selected. Is there properties like "SelectedItem" or "IsSelected" for XamWebChart?
You can use the following code to retrieve the clicked column's bind item
((e.Element as ColumnChartDataPointTemplate).Series.DataSource as List<DataPointData>)[(e.Element as ColumnChartDataPointTemplate) .Series.DataPoints.IndexOf(((e.Element as ColumnChartDataPointTemplate).DataPoint))]
Hi Fang,
Currently there are no built in methods/properties to achieve the desired functionality you are after. You will have to use your own methods in order to achieve the selection you want, as well as retrieving information about the data point that you clicked on. Sorry for the inconvenience.
-Marisa
Hallo Marisa and amitatsodel,
Thank you for your replies! It helps.
When I click on one datapoint, I want to change this datapoint into a selection style and clear the selection style of other datapoints.
And when I set the DataSource of the XamWebChart to an object, new ObservableCollection<DataPointData>(), then each datapoint is corresponding to a DataPointData. When I click on one datapoint, I want to get this DataPointData for the datapoint.
Sure these can be implemented, but it would be very nice that XamWebChart contains such methods or properties to get the source of the datapoint directly and implements the datapoint selection functionality.
Fang
Hi jifangeva,
You can hook up the DataItemMouseLeftButtonDown event on your XamWebChart and use that to figure out what element you're clicking on. If the element is a ColumnChartDataPointTemplate, you can get that element and set the style as necessary. Here's what I did:
private void Chart1_DataItemMouseLeftButtonDown(object sender, DataItemMouseEventArgs e) { if (e.Element as ColumnChartDataPointTemplate != null) { ColumnChartDataPointTemplate dataPointTemplate = (ColumnChartDataPointTemplate)e.Element; dataPointTemplate.Fill = new SolidColorBrush(Colors.Green); } }
Hope this helps!
Marisa
Hi
I think you can use DataItemMouseLeftButtonUp() event of that chart. This event gets fired when you click on any column.