使用JSON数据表返回的Google差异图表[给定轴上的所有系列必须具有相同的数据类型]

时间:2015-01-13 06:09:47

标签: javascript json charts google-visualization

我正在尝试生成差异图表,以使用Google Visualization比较两组数据。 (https://developers.google.com/chart/interactive/docs/gallery/diffchart

数据A: {"cols":[{"label":"Month","type":"string"},{"label":"Total","type":"number"},{"type":"string","role":"style","p":{"role":"style"}}],"rows":[{"c":[{"v":"8","f":"2014-08"},{"v":"68435.52"},{"v":"orange"}]}]}

数据B: {"cols":[{"label":"Month","type":"string"},{"label":"Total","type":"number"},{"type":"string","role":"style","p":{"role":"style"}}],"rows":[{"c":[{"v":"9","f":"2014-09"},{"v":"67348.25"},{"v":"orange"}]}]}

但每当我绘制图表时,我都会收到此错误:

all series on a given axis must be of the same data type

这是我的代码:

var dataA = new google.visualization.DataTable(data1);
var dataB = new google.visualization.DataTable(data2);

var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));

var diffData = chart.computeDiff(dataA, dataB);

 chart.draw(diffData);

-
编辑:

的jsfiddle http://jsfiddle.net/9svvm1rj/

1 个答案:

答案 0 :(得分:0)

在摆弄我的JS之后,我发现“样式”列({"type":"string", "role":"style"})导致了问题。

我不知道这是否是谷歌图表API上的错误,或者它是一个尚未实现的功能,所以现在我删除了它的风格并且它有效。

这是工作小提琴:http://jsfiddle.net/nb795hyx/