问题
I want to add a redraw function on highchart to show a new set of data for a series, iv made the button but the code behind am struggling.
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'
}
});
where does the redraw method go, and how would i call it to redraw new data when the button is clicked.
i now have this updated
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();
However I need to get the same data from the chart; instead of deleting the series, I need it to add data from the existing chart, so I can call it from vb.net code
UPDATE FIDDLE:
jsfiddle
回答1:
use redraw(), because addSeries() has included redraw function.
http://api.highcharts.com/highcharts#Chart.addSeries()
回答2:
Instead of remove and add new Series, you can use setData() http://api.highcharts.com/highcharts#Series.setData() function. If you use addSeries() you don't need to use redraw(), because addSeries() has included redraw function.
http://api.highcharts.com/highcharts#Chart.addSeries()
回答3:
If I understand correctly, you are saying that pressing the button isn't loading new series.
If that is it, then it's because you are setting up the button click
handler inside the change
handler. Meaning you'd have to click on B or C radion buttons before it was registered. Move it out of the change
handler like this and it'll work.
来源:https://stackoverflow.com/questions/17472323/use-redraw-to-get-data-from-chart-jsfiddle-provided