This is a migrated thread and some comments may be shown as answers.

ChartView Interactivity & Events

6 Answers 83 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Colter
Top achievements
Rank 1
Colter asked on 14 May 2013, 05:43 PM
Hello Telerik,

I've been working with the Telerik ChartView for the past week or so and have been writing a thin layer overtop of the controls so that I may have a simplified Chart User Control with a more limited set of configurable functionality.

I'm now trying to expose events in the chart but can only find the SelectionChanged event in the ChartView API.

How would I get MouseEnter, MouseLeave, Click events on individual series elements?

I've tried a few different things to do this, mainly I've tried to grab the underlying Framework element and tried to attach event handlers to it (see below).  

private void BindSeriesElements(ChartSeries series)
{
    if (series is BarSeries)
    {
        var barSeries = series as BarSeries;
         
        foreach (var dataPoint in barSeries.DataPoints)
        {
            UIElement element = barSeries.GetDataPointVisual(dataPoint);
            element.MouseEnter += element_MouseEnter;
        }
    }
}

However, these events never get fired (I suspect that there is a transparent element sitting overtop of the chart preventing event propagation).  Is there a way that I can work around this?  Are there events somewhere within the ChartView namespace that I can tap into at the DataPoint level?

Regards,

Colter


6 Answers, 1 is accepted

Sort by
0
Accepted
Rosko
Telerik team
answered on 16 May 2013, 03:50 PM
Hi Colter,

The missing step is that you need to set the IsHitTestVisible property of the respective series to true. After this, you can get all the event that are related to UIElement. This way you will not really need to use the selection changed event and it will allow you better abstraction.

This can be done either in C# or XAML.
barSeries.IsHitTestVisible = true;

<telerik:BarSeries IsHitTestVisible="True">

In case you will be using a continuous series, you need to set a point template for the series. Over there, you can set all the events, you would like to use. In this help topic, you can find an example of that.

All the best,
Rosko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Colter
Top achievements
Rank 1
answered on 16 May 2013, 06:31 PM
Hey Rosko,

Ya that did the trick.  Perfect.

One more question though:

I can get the visual element attached to any of the series that are derived from PointTemplateSeries (i.e. bar, scatter, line etc).  However, how do I get the visual element attached do a PieDataPoint which inherits from SingleValueDataPoint?  How do I attach event handlers to pie slices?

Regards,

Colter
0
Rosko
Telerik team
answered on 22 May 2013, 07:52 AM
Hi Colter,

There is a reason why we have split our chart control in different subconrols. Each type has it own specifics, which requires different approaches. Making an abstraction to that is extremely hard and would not give optimal results. That is why there is such difference between RadChart, where all types are fitted in one control, and RadChartView. In the case of the pie chart, the slices are segments of one big Path. The scenario you are asking for is not supported. It is not adviceable to abstract RadChartView.

Greetings, Rosko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Colter
Top achievements
Rank 1
answered on 22 May 2013, 04:36 PM
Thanks Rosko,

I've managed to work around the issue I was having.  I noticed in the documentation that it is recommended to use the RadChartView as it is the newer implementation of charting and has better performance than the RadChart.  Are there any other distinct advantages to the new RadChartView architecture?  And just out of curiosity, how come the RadPieChart doesn't expose the UI elements attached to each pie slice in the same way that the RadCartesianCharts do?  I get that different charts have different requirements and the reason for splitting it up, but I don't understand why the underlying visual element is exposed in one chart type and not in the other.

Regards,

Colter
0
Rosko
Telerik team
answered on 27 May 2013, 10:43 AM
Hello Colter,

The reason that the UI elements are exposed in the Cartesian chart is that there was demand for that. On the other hand, until now, there was no demand for that in the Pie chart.

Regards, Rosko
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Colter
Top achievements
Rank 1
answered on 27 May 2013, 06:28 PM
Thanks for the replies Rosko,

Fair enough.  I guess I just thought it was weird that you would only want the ability to attach UI Event handlers to particular types of charts.  Anyways, thanks for the help.

Colter
Tags
ChartView
Asked by
Colter
Top achievements
Rank 1
Answers by
Rosko
Telerik team
Colter
Top achievements
Rank 1
Share this question
or