将项目重新绘制到highstock时,滚动条预览会消失

时间:2012-03-01 19:45:18

标签: highcharts highstock

我在highsoft使用highstock(http://highslide.com/)。

我正在尝试允许用户更改图表类型(样条线,直线,区域线等)。我这样做是通过重置选项,弹出系列中的项目并将它们重新添加到系列中。它很好用,除了重新添加所有内容时滚动条预览消失。任何帮助将非常感谢。这是我的代码:

    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;
        }   
    },  

1 个答案:

答案 0 :(得分:0)

好的想出来......

我意识到“导航器”成为系列项之一,我在while循环中将其删除。所以现在我只需弹出系列中名称不是“导航器”的所有项目。