谷歌图表 如何将变量传递给数据视图计算列函数?



根据Google的说法,DataView可用于动态计算列值。 (请参阅文档(

var myValue = 100;
var view = new google.visualization.DataView(data);

view.setColumns([
data.getColumnIndex('PART'),
data.getColumnIndex('VALUE'), 
{ calc:  exampleFromGoogle, type: 'number'},
{ calc:  customWithExternalValues, type: 'number'},
]);

谷歌计算示例不使用任何外部值,并且是自包含的。

function exampleFromGoogle(dataTable, rowNum) {     
return Math.floor(dataTable.getValue(rowNum, 1) / 2.54);
}

我想向 calc 函数传递一个变量myValue但我不知道调用计算函数的语法。{ calc: customWithExternalValues, type: 'number'}

这是我希望使用的功能。

function customWithExternalValues(dataTable, rowNum, myValue) { 
return (Math.floor(dataTable.getValue(rowNum, 1) / 2.54))* myValue;
}

我怎样才能做到这一点?

任何想法都非常感谢...谢谢!

在示例函数中使用自定义函数...

var myValue = 100;
var view = new google.visualization.DataView(data);
view.setColumns([
data.getColumnIndex('PART'),
data.getColumnIndex('VALUE'), 
{ calc:  exampleFromGoogle, type: 'number'},
{ calc:  exampleFromGoogle, type: 'number'},
]);
function exampleFromGoogle(dataTable, rowNum) {
return customWithExternalValues(dataTable, rowNum, myValue);
}
function customWithExternalValues(dataTable, rowNum, myValue) {
return (Math.floor(dataTable.getValue(rowNum, 1) / 2.54)) * myValue;
}

最新更新