当我在highstock图表中设置多个系列类型时,显示错误的数据

时间:2016-05-12 07:36:58

标签: highcharts highstock

我尝试制作一个包含多个系列类型,行和列的图表。 例如:Jsfiddle

$(function () {
var seriesOptions = [],
    seriesCounter = 0,
    names = ['MSFT', 'AAPL', 'GOOG'];

/**
 * Create the chart when all data is loaded
 * @returns {undefined}
 */
function createChart() {

    $('#container').highcharts('StockChart', {

        rangeSelector: {
            selected: 4
        },

        yAxis: {
            labels: {
                formatter: function () {
                    return (this.value > 0 ? ' + ' : '') + this.value + '%';
                }
            },
            plotLines: [{
                value: 0,
                width: 2,
                color: 'silver'
            }]
        },

        plotOptions: {
            series: {
                compare: 'percent'
            }
        },

        tooltip: {
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
            valueDecimals: 2
        },

        series: seriesOptions
    });
}

$.each(names, function (i, name) {

    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?',    function (data) {

        seriesOptions[i] = {
            name: name,
            data: data,
        };
        if(name == 'GOOG'){
            seriesOptions[i].type = 'column';
        }

        // As we're loading the data asynchronously, we don't know what order it will arrive. So
        // we keep a counter and create the chart when all the data is loaded.
        seriesCounter += 1;

        if (seriesCounter === names.length) {
            createChart();
        }
    });
});

});

当我没有缩放时,我有错误的数据(超过正常值),当我放大时,我有良好的数据。

有什么问题?我不知道为什么系列类型可以改变数据

谢谢你的帮助!

1 个答案:

答案 0 :(得分:3)

默认情况下,Highstock使用dataGrouping,它根据单位对点进行分组。您可以通过参数禁用它。

plotOptions:{
   series:{
      dataGrouping:{
          enabled: true
      }
   }
}