1)我在代码中获得Uncaught TypeError: undefined is not a function
,如:
var moneyFormat = new google.visualization.TableNumberFormat({prefix: '$', fractionDigits: '2'})
2)我的图表也停止显示,这里有一些可以在visualization playground中使用的示例代码:
function drawVisualization()
{
//Area Chart - Monthly Revenue(yoy)
var revenueData = new google.visualization.DataTable();
revenueData.addColumn('string', 'Month');
revenueData.addColumn('number', new Date().getFullYear());
revenueData.addColumn('number', new Date().getFullYear() - 1);
revenueData.addRow(['remove', 0, 0]);
var revnueOptions = {
animation: {duration: 450, easing: 'inAndOut',},
hAxis: {title: 'Months', titleTextStyle: {color: '#546892'}},
vAxis: {title: 'Revenue', titleTextStyle: {color: '#546892'}},
colors: ['#6B9EB8', '#BDBDBD']
};
var revenueChart = new google.visualization.AreaChart(document.getElementById('visualization'));
revenueChart.draw(revenueData, revnueOptions);
revenueData.removeRow(0);
revenueData.addRows([["Jan",476720.91,312755.59],["Feb",257814.89,262533.76],["Mar",314711.67,212908.66],["Apr",467195.04,280168.64],["May",378582.63,234551.38],["Jun",423507.6,223820.38],["Jul",354414.55,239495.22],["Aug",276546.96,215121.71],["Sep",301605.96,414958.25],["Oct",536133.65,315029.05],["Nov",533505.83,560722.95],["Dec",0,815092.65]]);
revenueChart.draw(revenueData, revnueOptions);
}
答案 0 :(得分:3)
Google于2013年11月26日发布了一些更新。
问题1
:
您应该使用NumberFormat
代替TableNumberFormat
。请参阅:google.visualization.NumberFormat
问题2
:
行:
revenueData.addColumn('number', new Date().getFullYear());
revenueData.addColumn('number', new Date().getFullYear() - 1);
将数字作为第二个参数传递,这会导致错误。您可以添加空字符串+''
或调用.toString()
将其解析为字符串,如下所示:
revenueData.addColumn('number', (new Date().getFullYear())+'');
revenueData.addColumn('number', (new Date().getFullYear() - 1).toString());
在它们允许你在第二个参数中传递数字之前,现在它们只强制执行字符串。