gpt4 book ai didi

javascript - Highstock basemap 未显示

转载 作者:行者123 更新时间:2023-11-28 04:59:59 26 4
gpt4 key购买 nike

我正在使用官方 highstock 图表 demo创建类似的东西,将 2 个图表堆叠在一起。问题是底部图表(成交量)未显示jsfiddle

aapl-ohlc.json的简要说明文件会有帮助。

...    
const data = JSON.parse(document.getElementById('ohlc-data').innerHTML);


// split the data set into ohlc and volume
const ohlc = data.map((a) => [a[0], a[1], a[2], a[3], a[4]])
const volume = data.map((a) => [a[0], a[5]])

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

// create the chart
Highcharts.stockChart('container', {
legend: {
enabled: false
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
scrollbar: {
enabled: false
},
rangeSelector: {
selected: 4,
inputEnabled: false
},

title: {
text: ''
},

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

tooltip: {
split: true
},

series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}],
navigator: {
enabled: false

}
});

最佳答案

这一行:

const volume = data.map((a) => [a[0], a[5]])

指向不存在的元素。 a[5] 未定义(每个子数组只有五个元素,没有第六个元素),因此数据中没有 y 值,因此没有要显示的数据系列。

我不知道什么数据元素应该代表体积,但作为引用,只是为了表明它确实有效,这里是一个使用

更新的 fiddle
const volume = data.map((a) => [a[0], a[1]])

编辑:

请注意,在您基于 fiddle 的演示示例中,他们使用的文件是 aapl-ohlcv.json,而不是 aapl-ohlc.json,后者事实上,每个子数组中都有第 6 个数据元素。

关于javascript - Highstock basemap 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42205771/

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