Sign in to follow this  
kon

Toggleable Series

Recommended Posts

I wrote some javascript code to toggle series in a multiseries graph, not sure if it works with all of them, i only used it with MSCombi3D.swf.

 

$j is the jQuery object obviously, replace with $ or jQuery if you use something different.

 

If someone has a simpler or more effective way of doing this please post here. Also suggestions and comments are welcome.

 


$j(chart.options.containerElement).data("origData", JSON.stringify(chart.getJSONData()));
var seriesList = $j("<ul class=\"seriesSelect\" />");
$j(chart.getJSONData().dataset).each(function (index, dataset) {
   var li = $j("<li />");
   var checkbox = $j("<input checked=\"checked\" rel=\"" + dataset.seriesname + "\" type=\"checkbox\" id=\"series_cb_" + dataset.seriesname + "\" /><label for=\"series_cb_" + dataset.seriesname + "\">" + dataset.seriesname + "</label>");
   checkbox.click(function (e) {
       var origData = JSON.parse($j(chart.options.containerElement).data("origData"));
       var origDataset = origData.dataset;
       var enabledSeries = [];
       //push all checked series into enabledSeries array
       $j(this).closest("ul").find("input:checked").each(function (i, input) {
           enabledSeries.push($j(this).attr("rel"));
       });
       origData.dataset = origDataset.filter(function (ele) {
           for (key in enabledSeries) {
               if ($j.trim(ele.seriesname) === enabledSeries[key]) {
                   return true;
               }
           }
           return false;
       });
       chart.setJSONData(origData);
   });
   checkbox.appendTo(li);
   li.appendTo(seriesList);
});

Edited by kon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this