拖动数据点并提交值
在页面 jqPlot 上有一个在 jqPlot 图表上拖动数据点的示例。
我如何提交(例如使用 jQuery ajax)到服务器更改的值?更改的(当前)值是否存储在 jqplot 对象中的某处?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里最难的事情是知道用户何时拖动一个点,而不是事后获取数据。我建议您使用 postDrawSeries 挂钩,如下所示:
每次拖动的输出为(包含更新的数据点):
Here's一个例子。(你必须在浏览器中缓存 jqPlot js 文件,因为它们不允许热链接。)
你必须实现某种计时器来等待 5 秒左右,然后再执行调用 ajax 因为 postdrawseries 钩子会在每个拖动事件上触发。但这应该不会太难。
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:
Output on every drag is (containing the updated data point):
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.
postDrawSeriesHooks 的问题在于,它在您单击图表的整个过程中都会运行。如果您正在进行 ajax 调用,这可能会造成真正的混乱。我会将 jqplotClick 事件绑定到您的图表。您甚至可以到达特定点,或者每次都可以保存所有数据。但每次点击只会保存一次。
这里是一个包含多个图表的示例,每次单击都会对 php 文件进行 ajax 调用,并存储两个图表中的所有数据点。但这只允许每个图有一个系列。
The problem with postDrawSeriesHooks is that it runs the entire time you are clicking on the graph. This could be a real mess if you are making ajax calls. I would bind the jqplotClick event to your chart instead. You can even get to specific point or you can save all of the data each time. But it will only get saved once per click.
Here an example with multiple graphs that makes an ajax call to a php file every click and stores all the data points from both graphs. This only allows for a single series for each plot though.
这个答案确实对我们有帮助。
我注意到还有另一个钩子,jqplotDragStop。
所以通过使用这个,我们可以在每次拖动停止时调用ajax。这正是我们所寻找的。
希望这会有所帮助(抱歉,不知道如何添加评论,这是 stackoverflow 的新手)。
This answer really helped us.
I noticed there is another hook, jqplotDragStop.
So by using this, we can call ajax every time the dragging stops. Just what we were looking for.
Hope this helps (Sorry, could not figure out how to add a comment, new to stackoverflow).