ChartView Interactivity & Events

7 posts, 1 answers
  1. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 14 May 2013 Link to this post

    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


  2. Answer
    Rosko
    Admin
    Rosko avatar
    137 posts

    Posted 16 May 2013 Link to this post

    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.

  3. DevCraft banner
  4. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 16 May 2013 Link to this post

    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
  5. Rosko
    Admin
    Rosko avatar
    137 posts

    Posted 22 May 2013 Link to this post

    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.

  6. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 22 May 2013 Link to this post

    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
  7. Rosko
    Admin
    Rosko avatar
    137 posts

    Posted 27 May 2013 Link to this post

    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.

  8. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 27 May 2013 Link to this post

    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
Back to Top
DevCraft banner