javascript - 如何减少蜡烛之间的 HighStock 图表差距?
问题描述
我正在使用 HighChart-HighStock 的烛台图。我想缩小烛台之间的差距。当它在大范围变焦时还不错。但是当我放大图表很多时,蜡烛之间的填充让我很恼火,因为它们之间的距离太远了。
我尝试设置to ,但什么pointPadding
也没发生。我怎样才能缩小这个差距?plotOption&xAxis
0
缩放图表 - 烛台之间的差距过大
宽视图图表 - 还不错
Highcharts.stockChart('container', {
// title: { text: '---'},
rangeSelector: {
buttons: [
// { type: 'hour', count: 1, text: '1h' },
{
type: 'day',
count: 1,
text: '1d'
},
// { type: 'all', count: 1, text: 'All' }
],
selected: 1,
//inputEnabled: true
},
xAxis: [{
pointPadding: 0,
type: 'datetime',
}, {
type: 'datetime',
}],
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '70%',
lineWidth: 2,
resize: {
enabled: true
}
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
top: '75%',
height: '25%',
offset: 0,
lineWidth: 2
}],
plotOptions: {
candlestick: {
pointPadding: 0,
downColor: 'blue',
upColor: 'red',
dataGrouping: {
enabled: false,
}
},
line: {
lineWidth: 1,
states: {
hover: {
enabled: false
}
}
}
},
series: [{
name: 'ohlc',
type: 'candlestick',
data: chartData,
},
{
name: 'avg5',
type: 'line',
data: avg5Data,
color: '#FF0000',
},
{
name: 'avg10',
type: 'line',
data: avg10Data,
color: '#0C9B3A',
},
{
name: 'avg20',
type: 'line',
data: avg20Data,
color: '#FF9900',
},
{
name: 'avg60',
type: 'line',
data: avg60Data,
color: '#000000',
},
{
name: 'vol',
type: 'column',
data: moneyData,
yAxis: 1,
color: '#0944a3',
dataGrouping: {
enabled: false,
}
}
],
});
}
解决方案
您需要设置series.pointPadding
组合与series.groupPadding
(等于零)才能达到预期的效果。这是示例:https ://jsfiddle.net/ahxrk5zq/
series: [{
type: 'candlestick',
name: 'AAPL Stock Price',
data: data,
groupPadding: 0,
pointPadding: 0.04,
dataGrouping: {
units: [
[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]
]
}
}]
API参考:
https://api.highcharts.com/highstock/series.candlestick.pointPadding
https://api.highcharts.com/highstock/series.candlestick.groupPadding
推荐阅读
- node.js - 使用 Electron BrowserWindow() 的电子滚动问题;
- javascript - 如果来自另一个数组的对象 id 值匹配,则替换数组内部的对象
- excel - 如何在多个范围内应用条件格式
- php - symfony 5 new Authenticator-based Security - createHasher() 必须是数组类型,给定对象
- ember.js - 如何从插件中的配置/环境访问 ENV?
- cuda - 仅在分配的一部分上使用 cudaHostRegister 是否安全?
- performance - 使用 GCC 覆盖检测工具编译/运行程序会消耗多少额外资源?
- python - 比较 R 和 Python 向量化和优化
- python - 烧瓶用一个列出清单
- azure - 由于方法 java.rmi.MarshalException 中的错误,无法从 azure 容器上的主节点运行 taurus 命令