我想在 highchart 上添加重绘功能以显示一系列新的数据集,iv 制作了按钮,但后面的代码很困难。
HTML:
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<button id="button">redraw </button>
JS:
function loadA(chart) {
chart.xAxis[0].update({
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
});
chart.yAxis[0].setTitle({
text: "kHw"
});
chart.addSeries({
name: 'Rainfall11',
type: 'column',
color: '#08F',
data: [100, 200, 300, 400, 100, 200, 0, 0, 0, 0, 0, 0]
});
chart.addSeries({
name: 'Rainfall2',
type: 'column',
color: '#808000',
data: [100, 200, 300, 400, 100, 200, 0, 0, 0, 0, 0, 0]
});
chart.addSeries({
name: 'Rainfall3',
type: 'column',
color: '#FFA500',
data: [100, 200, 300, 400, 100, 200, 0, 0, 0, 0, 0, 0]
});
}
$(function() {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
}
});
重绘方法在哪里,以及如何在单击按钮时调用它来重绘新数据。
我现在已经更新了
function redraw() {
// Delete all the series.
while (chart.series.length > 0) {
chart.series[0].remove(false);
}
// Add the new series.
chart.addSeries({ data: Highcharts.map(Array(12), Math.random) }, false);
// Redraw the chart.
chart.redraw();
但是我需要从图表中获取相同的数据;我不需要删除该系列,而是需要它从现有图表中添加数据,这样我就可以从 vb.net 代码中调用它
更新 fiddle :
最佳答案
使用redraw(),因为addSeries()已经包含了重绘功能。
关于javascript - 使用redraw从图表中获取数据,Jsfiddle提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17472323/