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

Select All / Deselect all legend items

3 Answers 281 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Chase
Top achievements
Rank 1
Chase asked on 11 Mar 2014, 06:44 PM
I'm working with a RadHtmlChart that has a lot of series running through it, and frequently, our users will want to be able to quickly select or deselect all the series in the legends, and then select the series they actually want to see.

I was wondering, how would I go about implementing  "select all" and "deselect all" options for the legend on the chart?

3 Answers, 1 is accepted

Sort by
0
Chase
Top achievements
Rank 1
answered on 13 Mar 2014, 04:53 PM
So, I just figured this out myself. Since there aren't any public facing methods for the legendItemClick event, I had to use private methods (not the best practice), but hey, it works:

<script type="text/javascript">
        function legendDeselectAll() {
            var chart = $find("Chart");
            if (chart != null) {
                for (counter = 0; counter < chart._chartObject.options.series.length; counter++) {
                    if (chart._chartObject.options.series[counter].visible) {
                        chart._chartObject._legendItemClick(counter);
                    }
                }
            }
        }

        function legendSelectAll() {
            var chart = $find("Chart");
            if (chart != null) {
                for (counter = 0; counter < chart._chartObject.options.series.length; counter++) {
                    if (!chart._chartObject.options.series[counter].visible) {
                        chart._chartObject._legendItemClick(counter);
                    }
                }
            }
        }
    </script>
0
Danail Vasilev
Telerik team
answered on 14 Mar 2014, 12:22 PM
Hi Chase,

The mentioned approach for hiding chart series on the client is a reasonable way. Another approach could be to set the visible property and the repaint the chart. For example:
function legendDeselectAll() {
    var chart = $find("Chart");
    if (chart != null) {
        for (counter = 0; counter < chart._chartObject.options.series.length; counter++) {
            if (chart._chartObject.options.series[counter].visible) {
                chart._chartObject.options.series[counter].visible = false;
                //chart._chartObject._legendItemClick(counter);
            }
        }
        chart.repaint();
    }
}

You may also find interesting this feedback item.

Regards,
Danail Vasilev
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Gabriel
Top achievements
Rank 2
answered on 08 May 2014, 04:48 PM
Hi Danail,

Just to point out that even if your adjustments make the script to run faster, and indeed when you put, lets say in a CheckBox, the DeselectAll all series are deselected, when you try to activate not by the function, just a particular Series by clicking in the legend on the chart, the first time you try to do this you have to double click in legend to accomplish this task, I don't know if there is an internal flag that doesn't know that the series is not visible, so I'll keep by now Chase's code.

Greetings
Gabriel
Tags
Chart (HTML5)
Asked by
Chase
Top achievements
Rank 1
Answers by
Chase
Top achievements
Rank 1
Danail Vasilev
Telerik team
Gabriel
Top achievements
Rank 2
Share this question
or