每当我在我的 highcharts 向下钻取函数中调用 series.remove() 时,图表系列就会被删除并按预期取消设置。但是,我需要存储原始图表数据以便“回溯”。
我已将数据保存到另一个变量中,但调用 remove 也会取消设置我存储在该变量中的数据。我猜它是以某种方式通过引用存储的?
我尝试使用 jquery 函数复制数据,但数据仍在被 highcharts series.remove() 函数擦除。
这是我的点击代码:
function() {
var drilldown = this.series.options.drilldownSeries;
if (drilldown) {
setChart(drilldown[this.category]);
}
else {
setChart('drillUp');
}
}
这是我的 setChart 代码:
window.rhChartDataBank = {};
function setChart(data) {
if (data !== 'drillUp'){
//HERE'S WHERE i TRY TO COPY THE DATA TO ANOTHER 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 = [];
for (var i = 0; i < data.length; i++) {
newCategories.push(data[i].data.x);
}
//Set new data
var newData = [];
for (var i = 0; i < 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 THE TIME THIS RUNS window.rhChartDataBank._originalData is full of only null values.
//Set old categories
var oldCategories = [];
for (var i = 0; i < window.rhChartDataBank._originalCategories.length; i++) {
oldCategories.push(window.rhChartDataBank._originalCategories[i]);
}
//Set old data
var oldData = [];
for (var i = 0; i < 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 FOR NOW SINCE I CAN'T GET DATA FROM ORIGINAL CHART...
var ddddata = [45,20,70];
hChart.addSeries({
type: 'column',
data: ddddata,
}, false);
hChart.redraw();
}
}