highcharts - Highcharts - 可调整大小的 y 轴作为烛台和交易量图表的一个
解决方案
调整大小适用于轴,并且系列可以分配给任何轴,因此如果您将在同一个 yAxis 中有多个系列,那么调整大小将适用于该 yAxis 中的所有系列。
音量的默认演示数据大约1 000 000
大于 OHLC 数据,所以我在下面的演示中进行了调整:https ://jsfiddle.net/BlackLabel/oegqudbz/
Highcharts.getJSON('https://www.highcharts.com/samples/data/aapl-ohlcv.json', function (data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
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) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] / 1e6 // the volume in milions
]);
}
// create the chart
Highcharts.stockChart('container', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 2,
resize: {
enabled: true
}
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
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,
dataGrouping: {
units: groupingUnits
}
}]
});
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.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: 600px; min-width: 310px"></div>
通过 draggable-pane 模块可以更改多少个窗格(或 yAxes)没有限制,因此您可以拥有超过 2 个轴和超过 2 个调整器,并且不仅仅是分配给一个调整器的 2 个轴。API 参考中的更多信息: https ://api.highcharts.com/highstock/yAxis.resize
推荐阅读
- javascript - 在正则表达式中添加“点空间”和“点换行” - Javascript
- c# - 悬停在 UserControl 中时的动画
- amazon-s3 - Apache Airflow S3 日志记录
- javascript - Vuejs 简单的共享数据对象类
- node.js - 使用云函数访问 Firebase 数据库
- javascript - jQuery AJAX 的 if else 语句未运行
- c# - 需要帮助将外部文件添加到组合框
- python - 使用 Python 3 和 SQLite 的批量插入性能不佳
- node.js - 使用 chai 的 API 单元测试给出错误的结果
- css - 如何使用 CSS 网格设置粘性列?