如何通过单击jqplot条形图中的栏来获取ticklabels名称

时间:2017-02-10 13:55:50

标签: javascript jquery jqplot

我有一个jqplotbar图表,我的问题是,当我点击其中一个栏时,它应该显示刻度标签名称。它正如我想要的那样工作。但同时我也要显示刻度名称。但是我可以这样做.plz帮帮我

enter code here
    <!DOCTYPE html>
    <head>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

      <script type="text/javascript" src="te/jquery.jqplot.js"></script>
          <script type="text/javascript" src="te/plugins/jqplot.barRenderer.js"></script>
        <script type="text/javascript" src="te/plugins/jqplot.json2.js"></script>
        <link rel="stylesheet" type="text/css" href="te/jquery.jqplot.css" />
        <script language="javascript" type="text/javascript" src="te/plugins/jqplot.categoryAxisRenderer.js"></script>
         <script type="text/javascript" src="te/plugins/jqplot.json2.js"></script>
            <script type="text/javascript" src="te/plugins/jqplot.canvasTextRenderer.js"></script>
          <script type="text/javascript" src="te/plugins/jqplot.canvasAxisLabelRenderer.js"></script>
                 <script type="text/javascript" src="te/plugins/jqplot.canvasAxisTickRenderer.js"></script>
         <script type="text/javascript" src="te/plugins/jqplot.pointLabels.js"></script>
           <script type="text/javascript" src="te/plugins/jqplot.cursor.js"></script>
           <script type="text/javascript" src="te/plugins/jqplot.highlighter.js"></script>
             <script type="text/javascript" src="te/plugins/jqplot.dateAxisRenderer.js"></script>

        <script>

     $(document).ready(function(){
    var s1 = [2, 6, 7, 10];
    var s2 = [7, 5, 3, 2];
    var ticks = ['a', 'b', 'c', 'd'];

    plot2 = $.jqplot('chart2', [s1, s2], {
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            pointLabels: { show: true }
        },
    legend: {
            show: true,
            location: 'e',
    //marginTop : "1620px",

            placement: 'outside'
        }  ,
   series:[{label:'Present'}, {label:'Absent'}  ],
   axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            }
           },


          });

       $('#chart2').bind("jqplotClick", function(ev, seriesIndex, pointIndex, data) {


        alert('Plot Label: '+plot2.series[data.seriesIndex].label);
      });
    });

       </script>
     </head>
            <body>
            <div id="chart2" style="height:400px;width:95%; "></div>
          <p id='info2'></p>
         </body>
         </html>

1 个答案:

答案 0 :(得分:0)

从另一个答案。我已经尝试过,它可以正常工作

plot1.legend.labels[seriesIndex]

Source