本文介紹了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 在數據點上添加點擊事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!