Chart legend item click ...

7 posts, 0 answers
  1. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 29 Jul 2010 Link to this post

    I have a pie chart with interactivity features enabled.  Clicking on a slice of the pie will cause that slice to detach (explode) and send me a chart area item click event.  If I click on an item in the legend, the pie slice still detaches, but I can't find the corresponding event.

    Is there an event that I can catch when a user clicks a legend item ?

    Thanks
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 30 Jul 2010 Link to this post

    Hello scott,

    Currently this is not supported but we are planning to extend the Interactivity API and possibly add some events for the next release of the control. Could you elaborate a bit what kind of functionality would be useful for you from code-behind aside from a legend item click notification?


    Greetings,
    Freddie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 30 Jul 2010 Link to this post

    Hi Freddie.  I'm thinking how to work around several issues.  I've attached a png picture of a couple of controls containing radcharts.  The left chart shows a pie with the pink slice selected.  Clicking that slice selects or unselects it.  I catch the click event in a chart area click handler.   When you act on the left hand chart, the right hand chart changes may filter itself based on your selection.  The rad expanders that you see (center right in each chart) let you drill in N levels deep based on various fields in an underlying radgrid (not shown). 

    Each control knows who its parent is and who its child is.  When constructed, the control needs to know what its parent has selected, if anything.

    Issue 1:  There isn't a way to ask the radchart what is selected, so I have to implement that logic myself in my control by saving the information about the clicked datapoint when the chart area click handler runs.

    void ChartArea_ItemClick(object sender, Telerik.Windows.Controls.Charting.ChartItemClickEventArgs e)
    {
        DataPoint dp = e.DataPoint;
        if (dp.DataItem.ToString() == "All Others")
        {
            MessageBox.Show("Can't drill into All Others.");
            return;
        }
        selectedSlice = dp.DataItem.ToString(); 
        if (selectedSlice == lastSelectedSlice)
        {
            // simulate unselect
            selectedSlice = "";
        }
        else
        {
            // but if we actually selected something different then zap all child drill down selects
            myManager.ClearAllChartSelects(this);
        }
        lastSelectedSlice = selectedSlice;
        InitializeTitle();
        if (childChart != null)
            childChart.ReDraw();


    Issue 2:  If the user clicks on a legend item, the appropriate slice is selected or unselected and the visuals change, but there is no event that I can catch to notify me to redraw the charts.  This causes the logic to become out of sync with the visuals.

    Notice the checkboxes labeled "Bar" in the picture ?  Clicking those changes the charts from pie charts to bar charts.  If a user changes the chart type then the Bar checkbox handler has to ensure that whatever was selected in the pie ends up selected when the bar chart displays.

    Issue 3:  There isn't a way to tell the radchart what to select and I have no idea how to handle this.

    So, if I were requesting new features I guess I would ask for:

    1) A click event on legend item clicks
    2) A way to ask the chart what is selected
    3) A way to tell the chart what to select

    Thanks Freddie ...
  5. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 05 Aug 2010 Link to this post

    Hi scott,

    Thank you for elaborating on this.

    We have updated your Telerik points for the involvement and we will forward your feedback to our developers for further consideration.


    Greetings,
    Freddie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Baiju
    Baiju avatar
    3 posts
    Member since:
    Sep 2011

    Posted 20 Jan 2014 Link to this post

    I would like to get an update on this. How to get legend item details on legend click event. (We are using version 2013.2.724.40). 
  7. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 23 Jan 2014 Link to this post

    Hi Baiju,

    Could you elaborate a bit more in your requirement. Also have you just started using the RadChart control. If yes, I would suggest you to use the newer RadChartView control as all of our efforts are dedicated on it instead of the older RadChart.

    In case you want to use the RadChart you can either Retemplate the ChartLegendItem and attach a MouseLeftButtonDown event where you think is appropriate. The DataContext in the template is a DataPoint, or wait for the ChartLegend to get populated and search the visual tree to find the ChartLegendItems. Then you can apply your logic on attaching a click handler, again with the MouseLeftButtonDown event.
    You can see how the legend is retemplated in the demo below:
    http://demos.telerik.com/silverlight-old/#Chart/SimpleFiltering


    In case you want to use the newer control along with the RadLegend control you can take a look at this demo to see how the legend items templated:
    http://demos.telerik.com/silverlight/#ChartView/LargeData.

    Hope this helps.

    Regards,
    Peshito
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Bharat
    Bharat avatar
    5 posts
    Member since:
    Apr 2014

    Posted 01 Aug 2015 in reply to Peshito Link to this post

    i have found legend click and handle with followiing code

    function sky() {
                var chart = $find("ctl00_MainContent_RadHtmlChartSent");

                //attach an event handler
                chart._chartObject.bind("legendItemClick", function (e) {
                    var index = e.seriesIndex;
                    var series=chart._chartObject.options.series.length;

                    debugger;
                    for (var i = 0; i < series; i++)
                    {
                        if(i==index)
                        {
                            chart._chartObject.options.series[i].visible = true;
                        }
                        else
                        {
                            chart._chartObject.options.series[i].visible = false;
                        }
                    }
                    $find("ctl00_MainContent_RadHtmlChartSent").repaint();
                    e.preventDefault();
                });

     window.onload=sky;

     

     

     

Back to Top
DevCraft banner