Javascript Jqplot-单击某个点以将其从数据库中删除

Javascript Jqplot-单击某个点以将其从数据库中删除,javascript,html,jqplot,Javascript,Html,Jqplot,我有一个jqplot的例子,它在按钮()上处理onclick事件 我的目标是:单击一个点以获取其数据库id。然后我计划运行ajax,以便将其从db中删除。问题:如何将id放入图形中(不改变其外观),然后通过图形上的点onClick获取此id <script class="code" type="text/javascript"> //START - GRAPH ITSELF $(document).ready(function ()

我有一个jqplot的例子,它在按钮()上处理onclick事件

我的目标是:单击一个点以获取其数据库
id
。然后我计划运行ajax,以便将其从db中删除。问题:如何将id放入图形中(不改变其外观),然后通过图形上的点
onClick
获取此id

<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&nbsp;%#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>

//开始-图形本身
$(文档).ready(函数(){
变量行1=['08年5月23日',578.55],'08年6月20日',566.5],'08年7月25日',480.88],'08年8月22日',509.84],
[08年9月26日,454.13],[08年10月24日,379.75],[08年11月21日,303],[08年12月26日,308.56],
[09年1月23日,299.14],[09年2月20日,346.51],[09年3月20日,325.99],[09年4月24日,386.15];
变量plot1=$.jqplot('chart1',[line1]{
标题:“不重要:)”,
轴线:{
xaxis:{
渲染器:$.jqplot.DateAxisRenderer,
选择:{
格式字符串:'%b%#d'
}
},
亚克斯:{
选择:{
formatString:“€%.2f”
}
}
},
荧光灯:{
秀:没错,
SizedJust:9.5
},
光标:{
节目:假
}
});
//结束图
//开始-单击点事件
$(“#图表1”).bind('jqplotDataClick',
函数(ev、序列索引、点索引、数据){
//如果我能在这里得到点ID,我会运行一些ajax
}
);
//结束
});

我有个主意。这是一种变通方法,但效果很好:

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