javascript JqPlot 在数据点上添加点击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8152790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JqPlot add click event on data points
提问by themhz
I am trying to use jqplot http://www.jqplot.com/tests/cursor-highlighter.php. I have successfully installed it in my framework. But i need to push a click event on the data points in the chart.
我正在尝试使用 jqplot http://www.jqplot.com/tests/cursor-highlighter.php。我已经成功地将它安装在我的框架中。但是我需要在图表中的数据点上推送一个点击事件。
This is my code so far,
到目前为止,这是我的代码,
<script class="code" type="text/javascript">
$(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: 'Πωλ?σει? απ? 23-May-08 μ?χρι 24-Apr-09',
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: {
formatString: '%b %#d'
}
},
yaxis: {
tickOptions: {
formatString: '%.2f'
}
}
},
highlighter: {
show: true,
sizeAdjust: 9.5
},
cursor: {
show: false
}
});
$.jqplot.eventListenerHooks.push(['jqplotClick', myClickHandler]);
});
function myClickHandler(ev, gridpos, datapos, neighbor, plot) {alert(1);}
</script>
this is my attempt to add the click event
这是我尝试添加点击事件
$.jqplot.eventListenerHooks.push(['jqplotClick', myClickHandler]); and
function myClickHandler(ev, gridpos, datapos, neighbor, plot) {alert(1);}
回答by themhz
lol i have found it :). The answer was :
大声笑我找到了:)。答案是:
<script class="code" type="text/javascript">
$(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: 'Πωλ?σει? απ? 23-May-08 μ?χρι 24-Apr-09',
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: {
formatString: '%b %#d'
}
},
yaxis: {
tickOptions: {
formatString: '%.2f'
}
}
},
highlighter: {
show: true,
sizeAdjust: 9.5
},
cursor: {
show: false
}
});
/* CLICK CODE START*/
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
alert(1);
}
);
/* CLICK CODE END*/
});
</script>