需要创建一个类似于您在此处看到的图表:http://imgbin.org/index.php?page=image&id=20802 。到目前为止,我们已经成功地构建了一个显示两个图表的 jsfiddle,但它还远未完成。
如何正确地将底部图表(列)放置在第一个图表(列)上以实现示例中看到的效果? http://jsfiddle.net/e106L47h/6/
$(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', 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] // the volume
]);
}
// create the chart
$('#container').highcharts('StockChart', {
navigator: {
enabled: false
},
rangeSelector: {
selected: 1,
inputEnabled: false
},
credits: {
enabled: false
},
yAxis: [{
height: '60%',
lineWidth: 0
}, {
top: '65%',
height: '35%',
offset: 0,
lineWidth: 0,
// gridLineWidth: 0,
labels:
{
//enabled: false
}
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
});
最佳答案
我将删除高度 35%/65% 的分割并显示具有相同基线的两个系列。
然后我会隐藏音量轴以减少困惑。
您可以通过设置第二个隐藏轴的最大值而不是高度来修改音量条的高度(我使用 maxValue*3 来近似您的 35% 高度值)。
找到卷系列中的最大值,如下所示:
var maxVolume = Math.max.apply(Math, volume.map(function(v) { return v[1]}))
关于javascript - 如何使用 Highcharts 创建组合图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26800605/