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

Chart legend item click ...

8 Answers 527 Views
Chart
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 29 Jul 2010, 07:45 PM
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

8 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 30 Jul 2010, 11:18 AM
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
0
scott
Top achievements
Rank 1
answered on 30 Jul 2010, 07:09 PM
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 ...
0
Giuseppe
Telerik team
answered on 05 Aug 2010, 12:53 PM
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
0
Baiju
Top achievements
Rank 1
answered on 21 Jan 2014, 05:14 AM
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). 
0
Peshito
Telerik team
answered on 23 Jan 2014, 09:25 AM
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 >>
0
Bharat
Top achievements
Rank 1
answered on 01 Aug 2015, 09:12 AM

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;

 

 

 

0
Ranjith
Top achievements
Rank 1
answered on 21 Nov 2019, 06:42 AM

HI Giuseppe

    How do i disable the legendItemclick on kendo area chart? please provide me with an example dojo chart.

NOTE: Legend should be visible but it should not do any click event.

 

Thanks & Regards

Ranjith

0
Martin Ivanov
Telerik team
answered on 22 Nov 2019, 08:45 AM

Hello,

Please note that this is the UI for Silverlight forum section. If you have questions about Kendo UI, you can post them in the Kendo forum.

Regards,
Martin Ivanov
Progress Telerik

Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Chart
Asked by
scott
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
scott
Top achievements
Rank 1
Baiju
Top achievements
Rank 1
Peshito
Telerik team
Bharat
Top achievements
Rank 1
Ranjith
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or