gpt4 book ai didi

javascript - Highstock 上的多 Pane

转载 作者:行者123 更新时间:2023-12-02 23:57:57 24 4
gpt4 key购买 nike

我正在尝试使用 Highcharts 创建一个两 Pane 股票图表,就像这里的 http://www.highcharts.com/stock/demo/candlestick-and-volume/grid-light

我将 JSON 文件存储在此处 https://api.jsonbin.io/b/5c9499db08b9a73c3abeec4a .

当我运行我的项目时,我不知道为什么数据不能正常工作,并且小数值变大以及如何将时间序列与我的 7+ GMT 系列同步。

这是我的项目:

$.getJSON('https://api.jsonbin.io/b/5c9499db08b9a73c3abeec4a', function (data) {

var X = [],
Y = [],
temperature = [],
dataLength = data.length,

// set the allowed units for data grouping
groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]],

i = 0;

for (i; i < dataLength; i += 1) {
X.push([
data[i][0], // the date
data[i][1] // the X
]);
Y.push([
data[i][0], // the date
data[i][2] // the Y
]);

temperature.push([
data[i][0], // the date
data[i][3] // the temp
]);
}


// create the chart
Highcharts.stockChart('container', {

rangeSelector: {
selected: 1
},

title: {
text: 'AAPL Historical'
},

yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'X'
},
height: '60%',
lineWidth: 2,
resize: {
enabled: true
}
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'temp'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 2
}],

tooltip: {
split: true
},

series: [
{
type: 'line',
name: 'X',
data: X,
dataGrouping: {
units: groupingUnits
}
},
{
type: 'line',
name: 'Y',
data: Y,
dataGrouping: {
units: groupingUnits
}
},
{
type: 'line',
name: 'temp',
data: temperature,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/drag-panes.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>


<div id="container" style="height: 400px; min-width: 310px"></div>

最佳答案

您相对于数据定义了错误的 dataGrouping.units 数组。检查下面发布的示例。

代码:

$.getJSON('https://api.jsonbin.io/b/5c9499db08b9a73c3abeec4a', function(data) {

var X = [],
Y = [],
temperature = [],
dataLength = data.length,
groupingUnits = [
[
'millisecond', // unit name
[1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
],
[
'second', [1, 2, 5, 10, 15, 30]
],
[
'minute', [1, 2, 5, 10, 15, 30]
],
[
'hour', [1, 2, 3, 4, 6, 8, 12]
],
[
'day', [1]
],
[
'week', [1]
],
[
'month', [1, 2, 3, 4, 6]
],
[
'year',
null
]
],
i = 0;

for (i; i < dataLength; i += 1) {
X.push([
data[i][0], // the date
data[i][1] // the X
]);
Y.push([
data[i][0], // the date
data[i][2] // the Y
]);

temperature.push([
data[i][0], // the date
data[i][3] // the temp
]);
}

// create the chart
Highcharts.stockChart('container', {

yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'X'
},
height: '60%',
lineWidth: 2,
resize: {
enabled: true
}
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'temp'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 2
}],

tooltip: {
split: true
},

plotOptions: {
series: {
dataGrouping: {
units: groupingUnits
}
}
},

series: [{
name: 'X',
data: X
},
{
name: 'Y',
data: Y
},
{
name: 'temp',
data: temperature,
yAxis: 1
}
]
});
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/drag-panes.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>

演示:

API引用:

关于javascript - Highstock 上的多 Pane ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55295094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com