gpt4 book ai didi

javascript - Google 饼图 onclick 问题

转载 作者:行者123 更新时间:2023-12-02 19:01:23 25 4
gpt4 key购买 nike

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

        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)

}

点击饼图中的某个项目,我想获取相应的行号。我该怎么做。我尝试过,但是点击它就崩溃了。如何纠正它??

最佳答案

试试这个:

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

关于javascript - Google 饼图 onclick 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14768507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com