我有一个Highcharts折线图,我想为其添加范围选择器。为此,我读到您必须使用Highstock,因此我试图重新制作图表,但不会加载csv数据。控制台中没有错误消息或任何内容,只是这些行没有显示。我必须使用其他格式/语法吗?这是相关代码:
$(function() {
window.chart = new Highcharts.StockChart({
chart: {
renderTo: 'container'
},
title: {
text: 'My chart'
},
data: {
csv: document.getElementById('csv').innerHTML
},
});
});
谢谢!
答案 0 :(得分:0)
在Highchart和Highstock中加载数据的方法相同。注意,该数据需要另外加载数据模块。您的选择似乎不错,所以可能是问题所在。
Highcharts data documentation:
它需要加载modules / data.js文件。
查看演示:
https://jsfiddle.net/wchmiel/afy6m3tb/
HTML:
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<div id="container"></div>
<h3>Raw data</h3>
<pre id="data">Date,series A, series B, series C, series D, series E, series F
3/01/2001,100,100,100,100,100,100
4/01/2001,100.0723,100.0766,100.1225,100.1446,100.1687,100.1325
5/01/2001,100.0399,99.9775,100.0809,100.3502,100.1117,100.5127
6/01/2001,100.3103,100.3867,100.2974,100.5214,100.4256,100.6885
7/01/2001,101.3379,102.0689,100.686,100.6031,100.9522,100.7648
</pre>
JS:
window.chart = Highcharts.stockChart('container', {
data: {
csv: document.getElementById('data').innerHTML
}
});