2013-07-02 31 views
0

我需要createa圖表的多線highstock類型:你如何創建highstock在highcharts多線圖

我test.json文件看起來像這樣:

[{"name":"serverA","data":[[1372737609,2.6075],[1372737906,2.6533],[1372738205,2.7834],[1372738526,3.6527],[1372738802,0.6352],[1372739093,0.6073]]},{"name":"serverB","data":[[1372737602,36.3042],[1372737929,16.1145],[1372738218,6.4503],[1372738503,23.8908],[1372738803,3.9025],[1372739079,10.8216],[1372739371,3.1338]]},{"name":"serverC","data":[[1372737600,3.9025],[1372737908,13.8542],[1372738184,10.9094],[1372738491,14.6655],[1372738777,80.7615],[1372739081,6.9777],[1372739383,10.0971]]}] 

這是我的腳本:

(function() { 
    var seriesOptions = [], 
     yAxisOptions = [], 

     colors = Highcharts.getOptions().colors; 



     $.getJSON('test.txt', function(data) { 
      alert(data); 
      seriesOptions: data 
      createChart();  
     }); 

    // create the chart when all data is loaded 
    function createChart() { 

     $('#container').highcharts('StockChart', { 
      chart: { 
      }, 

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

}); 

我得到這個錯誤:

Uncaught TypeError: undefined is not a function 

任何想法我在這裏做錯了嗎?

回答

1

變化來自:到seriesOptions = data;

+0

我做了你的建議,仍然沒有圖。鑑於上述數據,您是否可以創建圖表? – user1471980

+0

您現在的位置是:http://jsfiddle.net/3bQne/277/還有兩件事情,可能是問題所在:確保您已經下載了Highstock現在的Highcharts,並且您在加載完畢後正在創建圖表。另外,在最後一行添加:'()'所以它會是:'})();' –