我正在使用 highsoft (http://highslide.com/) 的 highstock。
我试图让用户更改图表类型(样条、线、区域样条等)。我通过重置选项、将项目从系列中弹出并将它们重新添加到系列中来做到这一点。除了重新添加所有内容时滚动条预览消失之外,它运行良好。任何帮助将不胜感激。这是我的代码:
createChart: function(seriesOptions){
var cmp = this;
var chart_type = this.collection.chart_type;
if(!chart_type){
chart_type="line";
}
if(!cmp.chart){
var options = {
chart: {
renderTo: 'preview',
type: chart_type,
zoomType: 'x'
},
rangeSelector: {
selected: 4
},
plotOptions: {
series: {
point: {
events: {
click: function() {
console.log(this.config[0]);
}
}
}
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
yDecimals: 2
},
series: seriesOptions
};
cmp.chart = new Highcharts.StockChart(options);
}else{
while(cmp.chart.series.length>0){
cmp.chart.series[0].remove();
}
if(cmp.collection.compare_type=='percent'){
cmp.chart.options.plotOptions.series.compare = 'percent';
cmp.chart.options.tooltip.pointFormat = '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>';
}else{
cmp.chart.options.plotOptions.series.compare = undefined;
cmp.chart.options.tooltip.pointFormat = '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>';
}
_.each(seriesOptions, function(option){
option.type = cmp.collection.chart_type;
cmp.chart.addSeries(option, true, false);
});
cmp.chart.redraw();
//window.chart = cmp.chart;
}
},