Jqplot-单击一个点以将其从数据库中删除 [英] Jqplot - click a point to remove it from database
本文介绍了Jqplot-单击一个点以将其从数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用按钮上的onclick事件进行工作的jqplot示例( JqPlot在数据点上添加点击事件).
I have an example of jqplot with working onclick event on the buttons (JqPlot add click event on data points).
我的目标是:单击某个点以获取其数据库id
.然后,我计划运行ajax以便从数据库中删除它.问题:如何将id放入图形中(不改变其外观),然后通过图形上的点onClick
获取此ID.
My goal is this: click on a point to get it's database id
. Then I plan to run ajax in order to delete it from db. Problems: how to put id into graph (without changing it's looks), and then get this id via point onClick
on the graph.
<script class="code" type="text/javascript">
//START - GRAPH ITSELF
$(document).ready(function () {
var line1 = [['23-May-08', 578.55], ['20-Jun-08', 566.5], ['25-Jul-08', 480.88], ['22-Aug-08', 509.84],
['26-Sep-08', 454.13], ['24-Oct-08', 379.75], ['21-Nov-08', 303], ['26-Dec-08', 308.56],
['23-Jan-09', 299.14], ['20-Feb-09', 346.51], ['20-Mar-09', 325.99], ['24-Apr-09', 386.15]];
var plot1 = $.jqplot('chart1', [line1], {
title: 'Does not really matter :) ',
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: {
formatString: '%b %#d'
}
},
yaxis: {
tickOptions: {
formatString: '€%.2f'
}
}
},
highlighter: {
show: true,
sizeAdjust: 9.5
},
cursor: {
show: false
}
});
//END - GRAPH
//START - CLICK ON THE POINT EVENT
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
//if I could get point ID here I would run some ajax
}
);
//END
});
</script>
推荐答案
有一个主意.这是解决方法,但效果很好:
Got an idea. It is workaround, but works just fine:
var array_with_id_from_database = [1,4,7,9]; //order of id's the same as on graph... obviously
$('#chart').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
alert(array_with_id_from_database[pointIndex]);
//and when you have id you can ajax it from database, reload chart, and so on
}
);
为我自己感到骄傲:P
Proud of myself :P
这篇关于Jqplot-单击一个点以将其从数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文