本文介绍了JqPlot 在数据点上添加点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我正在尝试使用 jqplot http://www.jqplot.com/tests/cursor-highlighter.php.我已经成功地将它安装在我的框架中.但我需要在图表中的数据点上推送一个点击事件.
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.
这是我目前的代码,
<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);}
推荐答案
哈哈,我找到了 :).答案是:
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>
这篇关于JqPlot 在数据点上添加点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!