How to refresh jqplot bar chart without redrawing the chart
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a jqplot bar chart and I want the chart data to be changed when the user changes the value on a drop-down list. That works, but the problem is the bar chart redraws, one over another, each time the user changes the values.
How can I update or reload the bars without drawing the whole thing again? Is there any property value to be set?
Each time before redrawing the graph, just destroy the existing1.
$.ajax({ url: '/Home/ChartData', type: 'GET', data: { Id: Id }, dataType: 'json', success: function (data) { if(plot) { plot.destroy(); } var plot=$.jqplot('chartDiv', [a, b], CreateBarChartOptions(xAxis)); }});
回答4:
Took me a while to find an answer for the script generated data, so I'm going to post this right here. I used a combination of the above code.
I created a global var, named plot3 within my script file. Then created the below function. When this is called with a redraw boolean, it determines if I need to destroy and redraw or draw for the first time.
What first bit of code does is gets data from my jqgrid, (which is being updated in a different function), and updates the arrays. The second bit, determines my interval ticks, on the x-axis dependent upon my length of data.
function DrawGraph(bRedraw){ var testTimes = []; testTimes = $('#polarizationTable').jqGrid('getCol', 'TestTime', testTimes, false); var RdgA = $('#polarizationTable').jqGrid('getCol', 'RdgA', RdgA, false); var RdgB = $('#polarizationTable').jqGrid('getCol', 'RdgB', RdgB, false); var readingLineA = []; for (var i=0; i
回答5:
Here is a full example of how to dynamically update the plot with new data without reloading the page: