Kle*_*ios 5 highcharts highstock
默认的 highstock 图表具有高度 = 400px。
如何根据图表轴及其大小为自动大小设置高度图表?
请参见下面的示例,导航栏位于音量面板上方。
我知道我可以设置 div 的高度,但我有一个解决方案可以在图表中动态插入/删除轴/系列,并且自动高度图表会很好。
该示例与 Highchart 站点中的 Candlestick/Volume 演示相同,但在 div 容器中没有 height 属性。
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
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
])
}
// set the allowed units for data grouping
var groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
title: {
text: 'OHLC'
},
height: 200,
lineWidth: 2
}, {
title: {
text: 'Volume'
},
top: 300,
height: 100,
offset: 0,
lineWidth: 2
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
});
Run Code Online (Sandbox Code Playgroud)
问候。
Highcharts不支持动态高度,可以通过$(window).resize事件来实现:
$(window).resize(function()
{
chart.setSize(
$(document).width(),
$(document).height()/2,
false
);
});
Run Code Online (Sandbox Code Playgroud)
请参阅此处的演示小提琴。
| 归档时间: |
|
| 查看次数: |
18274 次 |
| 最近记录: |