Google Chart arrayToDataTable格式化值不起作用 [英] Google Chart arrayToDataTable formatted value not working

查看:62
本文介绍了Google Chart arrayToDataTable格式化值不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 arrayToDataTable ,并且该示例指出我可以使用格式化的值,例如:

I am followinf the google Chart documentation for arrayToDataTable and the example states that I can use formatted values, like that:

var data = google.visualization.arrayToDataTable([
['Employee Name', 'Salary'],
['Mike', {v:22500, f:'18,500'}],
...

其中 f:'18,500 是要显示的格式值。我的代码看起来完全相同:

where f:'18,500 is the formatted value to show. My code looks identical:

var data = google.visualization.arrayToDataTable([
['Category', 'Amount'],
['Food', {v:5595.819984, f:'5.595,82'}], 
['Home', {v:1890.530002, f:'1.890,53'}], 
['Mail', {v:8.380000, f:'8,38'}], 
['Train', {v:564.899998, f:'564,90'}], 
['Photo', {v:959.119995, f:'959,12'}], 
['Lego', {v:428.760004, f:'428,76'}], 
...

但图表甚至没有节目,崩溃。如果我取出格式化的数据,它会完美地工作。
我做错了什么?如何使用外观更好的版本在图表上显示值?

but the chart does not even shows, crashing. If I take out the formatted data, it works perfectly. What I am doing wrong? How can I use a better looking version to show the values on the chart?

推荐答案

正如安德鲁(Andrew)的评论中所提到的,Google文档似乎就在于此。

As mentioned in the comments by Andrew, Google Docs seem to lie on this one.

ArrayToDataTable()效果很好。由于添加其他格式会在数组中创建一个数组,因此Google似乎不喜欢它。如果要使用格式,则应按如下所示手动添加数据。

ArrayToDataTable() works great if you're passing in an array. Since adding the additional formatting creates an array in an array, Google doesn't seem to like it. If you want to use formats, you should add the data manually as follows.

您的代码:

var data = google.visualization.arrayToDataTable([
['Category', 'Amount'],
['Food', {v:5595.819984, f:'5.595,82'}], 
['Home', {v:1890.530002, f:'1.890,53'}], 
['Mail', {v:8.380000, f:'8,38'}], 
['Train', {v:564.899998, f:'564,90'}], 
['Photo', {v:959.119995, f:'959,12'}], 
['Lego', {v:428.760004, f:'428,76'}], 

更新后的代码:

var data = google.visualization.DataTable();
data.addColumn('string', 'Category');
data.addColumn('number', 'Amount');
data.addRows([
['Food', {v:5595.819984, f:'5.595,82'}], 
['Home', {v:1890.530002, f:'1.890,53'}], 
['Mail', {v:8.380000, f:'8,38'}], 
['Train', {v:564.899998, f:'564,90'}], 
['Photo', {v:959.119995, f:'959,12'}], 
['Lego', {v:428.760004, f:'428,76'}],
]);

这不会使您的数据添加变得过于复杂,最终会得到相同的结果,并且效果会更好带有格式值。

This won't overly complicate your data adding, will end with the same result, and will play nicer with formatted values.

这篇关于Google Chart arrayToDataTable格式化值不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆