我想将诸如 137.55 之类的值分配给谷歌图表中的“数字”类型列,然后绘制它。每当我分配浮点数时,它都会引发此异常:
Uncaught Error: Type mismatch. Value 32.03 does not match type number in column index 1
我的代码是这样的:
var data = new google.visualization.DataTable();
data.addColumn('number','Loop');
data.addColumn('number','ReqSec');
var myTicks = new Array();
var formatter = new google.visualization.NumberFormat({
fractionDigits: 2
});
for (var i=0;i<arr.length;i++){
myVal = $.trim(arr[i][10]);
myVal = parseFloat(Math.round(myVal * 100) / 100).toFixed(2);
data.addRow([parseInt(i), myVal]);
myTicks[i] = i;
}
formatter.format(data, 1);
// Create and draw the visualization.
new google.visualization.AreaChart(document.getElementById('visualization')).
draw(data, {curveType: "function",
width: 700, height: 400,
vAxis: {title: 'Throughput'},
hAxis: {title: 'Loop', ticks: myTicks}}
);
我尝试使用格式化程序,但我想它不是用于浮点数据类型插入。任何建议或解决方案?