On page jqPlot there is an example of dragging data point on jqPlot chart.
How can I submit (e.g. with jQuery ajax) to server changed values? Are changed (current) values stored somewhere in jqplot object?
The hardest thing here is knowing when the user drags a point, not getting the data afterward. I recommend you use a postDrawSeries hook like so:
$(document).ready(function () {
// set up plot
$.jqplot.config.enablePlugins = true;
s1 = [['23-May-08',1],['24-May-08',4],['25-May-08',2],['26-May-08', 6]];
plot1 = $.jqplot('chart1',[s1],{
title: 'Highlighting, Dragging, Cursor and Trend Line',
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: {
formatString: '%#m/%#d/%y'
},
numberTicks: 4
},
yaxis: {
tickOptions: {
formatString: '$%.2f'
}
}
},
highlighter: {
sizeAdjust: 10,
tooltipLocation: 'n',
tooltipAxes: 'y',
tooltipFormatString: '<b><i><span style="color:red;">hello</span></i></b> %.2f',
useAxesFormatters: false
},
cursor: {
show: true
}
});
// add our hook, to fire after a series update
$.jqplot.postDrawSeriesHooks.push(updatedSeries);
function updatedSeries(sctx, options) {
console.log(plot1.series[0].data); //data for the series is here
}
});
Output on every drag is (containing the updated data point):
[
Array[2]
,
Array[2]
,
Array[2]
,
Array[2]
]
Here's an example. (You'll have to cache the jqPlot js files in your browser since they do not allow hotlinking.)
You'll have to implement some sort of timer to wait for 5 seconds or so before calling your ajax since the postdrawseries hook fires on EVERY drag event. That shouldn't be too hard though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With