不同类型的高品质系列与json数据

时间:2016-01-27 10:50:19

标签: javascript jquery highcharts highstock

在下面的示例中,如何:

  • serie' MSFT'在类型行
  • serie' AAPL'在类型列
  • serie' GOOG'在类型样条曲线
$.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
        };

        // 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();
        }
    });
});

http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/stock/demo/compare/

2 个答案:

答案 0 :(得分:0)

也许你想要的是显示组合图表,这里是这个方案的一个例子。

http://www.highcharts.com/docs/chart-and-series-types/combining-chart-types

答案 1 :(得分:0)

只需创建一个types数组并在循环函数中使用它:http://jsfiddle.net/epaLtjre/

var seriesOptions = [],
    seriesCounter = 0,
    names = ['MSFT', 'AAPL', 'GOOG'],
    types = ['line', 'column', 'spline']; // add types

后来:

        seriesOptions[i] = {
            name: name,
            data: data,
            type: types[i] // apply type to the series
        };