php - highcharts series remove function deletes all original series data (even after stored in new variable) -
whenever call series.remove() in highcharts drilldown function chart series removed , unset expected. however, need store original chart data in order "drill up."
i've saved data variable, calling remove unsets data stored in variable. i'm guessing being stored reference somehow?
i've tried copy data using jquery function data still being wiped highcharts series.remove() function.
here's onclick code:
function() { var drilldown = this.series.options.drilldownseries; if (drilldown) { setchart(drilldown[this.category]); } else { setchart('drillup'); } }
and here's setchart code:
window.rhchartdatabank = {}; function setchart(data) { if (data !== 'drillup'){ //here's try copy data place if (window.rhchartdatabank._originaldata === undefined || window.rhchartdatabank._originalcategories === undefined){ var series0 = jquery.extend(true, {}, hchart.series[0].data), series1 = jquery.extend(true, {}, hchart.series[1].data); window.rhchartdatabank._originaldata = []; window.rhchartdatabank._originalcategories = []; window.rhchartdatabank._originaldata.push(series0); window.rhchartdatabank._originaldata.push(series1); window.rhchartdatabank._originalcategories = hchart.series[0].xaxis.categories; } //remove current series while(hchart.series.length > 0){ hchart.series[0].remove(false); } //set new categories var newcategories = []; (var = 0; < data.length; i++) { newcategories.push(data[i].data.x); } //set new data var newdata = []; (var = 0; < data.length; i++) { newdata.push(data[i].data.y); } hchart.xaxis[0].setcategories(newcategories, false); hchart.addseries({ type: 'column', data: newdata, }, false); hchart.redraw(); } else{ //remove current series while(hchart.series.length > 0){ hchart.series[0].remove(false); } //by time runs window.rhchartdatabank._originaldata full of null values. //set old categories var oldcategories = []; (var = 0; < window.rhchartdatabank._originalcategories.length; i++) { oldcategories.push(window.rhchartdatabank._originalcategories[i]); } //set old data var olddata = []; (var = 0; < window.rhchartdatabank._originaldata[0].length; i++) { olddata.push(window.rhchartdatabank._originaldata[0][i]['y']); } hchart.xaxis[0].setcategories(window.rhchartdatabank._originalcategories, false); //adding in dummy data since can't data original chart... var ddddata = [45,20,70]; hchart.addseries({ type: 'column', data: ddddata, }, false); hchart.redraw(); } }
since hchart.series
array, can clone array with
var backup_series = hchart.series.slice(0);
so can restore original series when needed.
Comments
Post a Comment