谷歌饼图 - onclick问题

时间:2013-02-08 08:29:37

标签: javascript jquery google-visualization

我正在创建像这样的谷歌饼图

        var totrefuelList=[{"veId":220,"trName":"Bus 04","totamt":2,"toqt":10.0},{"veId":384,"trName":"KL 20 B 3966","totamt":0,"toqt":430.00},{"veId":385,"trName":"KL 20 7511","totamt":0,"toqt":0.0},{"veId":386,"trName":"KL 20 D 7426","totamt":0,"toqt":0.0},{"veId":387,"trName":"KL 20 C 3985","totamt":0,"toqt":190.0},{"veId":388,"trName":"KL 01 AM 8356","totamt":0,"toqt":90.0},{"veId":389,"trName":"KL 01 C 8247","totamt":0,"toqt":234.0},{"veId":390,"trName":"KL 01 X 4435","totamt":0,"toqt":678.0},{"veId":391,"trName":"KL","totamt":768,"toqt":0.0},{"veId":392,"trName":"KL 20 B 7544","totamt":0,"toqt":67.0},{"veId":393,"trName":"KL","totamt":0,"toqt":0.0},{"veId":394,"trName":"KL","totamt":0,"toqt":460.0},{"veId":395,"trName":"KL","totamt":0,"toqt":56.0},{"veId":396,"trName":"KL","totamt":0,"toqt":78.0},{"veId":397,"trName":"KL","totamt":0,"toqt":890.0},{"veId":399,"trName":"KL","totamt":70,"toqt":88.0},{"veId":400,"trName":"KL 20 B 5478","totamt":0,"toqt":768.0},{"veId":401,"trName":"KL 01 D 6795","totamt":0,"toqt":760.0},{"veId":402,"trName":"KL","totamt":0,"toqt":0.0},{"veId":403,"trName":"KL 20 B 3968","totamt":0,"toqt":776.0},{"veId":398,"trName":"KL","totamt":1,"toqt":329.72972972972974}];
 function drawchartfromRefuel()
   {
    alert("RefuelLength"+totrefuelList.length);
    alert("veId:"+totrefuelList[0].veId);
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Task');
    data.addColumn('number', '');
    data.addRows(totrefuelList.length);
      for (var i=0;i<totrefuelList.length;i++)
        {
          data.setValue(i, 0, totrefuelList[i].trName);
          data.setValue(i, 1, totrefuelList[i].toqt);
        }

    var options = {
              title: 'Refuel Trend',
              height:'500',
              width:'400',
              backgroundColor: { fill:'transparent' }
            };

    var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
       google.visualization.events.addListener(chart, 'select', selectHandler);
    chart.draw(data, options);

   }

   function selectHandler(e) {
    var selection = chart1.getSelection();
    var item = selection[0];
    alert( item.row)

}

点击饼图中的项目,我想获得相应的行号。我怎么能这样做。我试过了,但是点击它frezzez ..如何纠正它?

1 个答案:

答案 0 :(得分:2)

试试这个:

google.visualization.events.addListener(chart, 'select', function(e) {
    var selection = chart.getSelection();
    console.log("selected row:", selection[0].row, data.getRow(selection[0].row));
});
相关问题