最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JqPlot add click event on data points - Stack Overflow

programmeradmin1浏览0评论

I am trying to use jqplot .php. I have successfully installed it in my framework. But i need to push a click event on the data points in the chart.

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

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.

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&nbsp;%#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);}
Share Improve this question asked Nov 16, 2011 at 13:56 themhzthemhz 8,42422 gold badges85 silver badges109 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

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&nbsp;%#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>
发布评论

评论列表(0)

  1. 暂无评论