javascript - High chart Categories work as Series Legend -


i display legend x-axis categories; series legend, , work in same way, turn category off in chart clicking on same category on legend.

what did following have charts can disable , enable categories of using jquery button , working fine .for now, disable , enable categories button click.

what want remove categories when click button , not disable only.in other words; want button work series legend buttons in highchart chart redraw .

example if click feb category feb disappear , have empty category between jan & march.and don't want . want chart redraw again without category.

$(document).ready(function () {     if ('@model.data' == "") return;     var title = '@model.title';     var x_axis_title = '@model.x_axis_title';     var y_axis_title = '@model.y_axis_title';     var chartcontainer = '@model.containername';     var chartcategories = [];     var chartcategoriesmaledata = [];     var chartcategoriesfemaldata = [];     var chartcategoriestotalmfdata = [];     var chartdata = [];     var seriesnames = [];     var chartdatastr = '@model.data';     var seriesnamesstr = '@model.seriesnames';     //alert("chartcontainer=" + chartcontainer);      function createdynamiccategories(chart, legendcontainerid) {         // capturing data chart options:         var categories = chart.options.xaxis.categories;         var series = chart.options.series;         // creating button  each category , place in container:         (var in chart.xaxis[0].categories) {             checkboxhtml = '<label><button type ="submit" onclick="onclick" id="category_' + + '">' + chart.xaxis[0].categories[i] + '</button></label>'             $('#' + legendcontainerid).append(checkboxhtml);         }         // binding events buttons:          $('#' + legendcontainerid + ' button[type ="submit"]').on('click', function () {             var buttonid = this.id;             alert(buttonid);             alert(buttonid.indexof('_'));             var strs = [];             var strs = buttonid.split('_');             alert(strs[1]);             var id = strs[1];             var hiddenseries = [];             var hiddencategories = [];              // collecting disabled categories:             hiddenseries[id] = null;             hiddencategories[id] = ' ';              // updating series data:             (var s in chart.series){                 chart.series[s].setdata($.extend([], series[s].data, hiddenseries));             }             // updating categories:             chart.xaxis[0].setcategories($.extend([], categories, hiddencategories));             // redrawing chart:             chart.redraw();         });     }     var chart = new highcharts.chart({         chart: {             renderto: chartcontainer,             defaultseriestype: 'bar'         },         title: {             text: 'monthly average rainfall'         },         subtitle: {             text: 'source: worldclimate.com'         },         xaxis: {             categories: [                 'jan',                 'feb',                 'mar',                 'apr',                 'may'             ]         },         yaxis: {             min: 0,             title: {                 text: 'rainfall (mm)'             }         },         legend: {             layout: 'vertical',             backgroundcolor: '#ffffff',             style: {                 left: 'auto',                 right: '30px',                 top: '70px',                 bottom: 'auto'             }         },         tooltip: {             formatter: function () {                 return '<b>' + this.series.name + '</b><br/>' +                 this.x + ': ' + this.y + ' mm';             }         },         plotoptions: {             column: {                 pointpadding: 0.2,                 borderwidth: 0             }         },         series: [{             name: 'tokyo',             data: [20, 71.5, 106.4, 129.2, 144.0]          }, {             name: 'new york',             data: [83.6, 78.8, 98.5, 93.4, 106.0]         }, {             name: 'london',             data: [48.9, 38.8, 39.3, 41.4, 47.0]         }, {             name: 'berlin',             data: [42.4, 33.2, 34.5, 39.7, 52.6]         }]     });     createdynamiccategories(chart, chartcontainer); }); 


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -