0

我是谷歌图表工具的新手,我想知道我做错了什么。我想通过添加 'isStacked':true 来堆叠 BarChart(或 ColumnChart),但是图表给了我错误的数据。

您可以使用此代码在 Google Playground 上自己尝试一下

(只需在选项中添加 'isStacked':true 即可查看错误结果)

function drawVisualization() {
// Create and populate the data table.
var  data = new  google.visualization.DataTable({"cols":[{"id":"","label":"Date","type":"string"},
                                                     {"id":"","label":"Complaints","type":"number"},
                                                     {"id":"","label":"Compliments","type":"number"},
                                                     {"id":"","label":"Questions","type":"number"},
                                                     {"id":"","label":"Suggestions","type":"number"}],
                                             "rows":[{"c":[{"v":"12\/2011"},{"v":30},{"v":0},{"v":0},{"v":0}]},
                                                     {"c":[{"v":"1\/2012"},{"v":93},{"v":"5"},{"v":0},{"v":0}]},
                                                     {"c":[{"v":"2\/2012"},{"v":82},{"v":"5"},{"v":0},{"v":0}]},
                                                     {"c":[{"v":"3\/2012"},{"v":72},{"v":"10"},{"v":0},{"v":0}]},
                                                     {"c":[{"v":"4\/2012"},{"v":68},{"v":"8"},{"v":0},{"v":0}]},
                                                     {"c":[{"v":"5\/2012"},{"v":59},{"v":"7"},{"v":0},{"v":0}]},
                                                     {"c":[{"v":"6\/2012"},{"v":30},{"v":"3"},{"v":"3"},{"v":0}]},
                                                     {"c":[{"v":"7\/2012"},{"v":37},{"v":"3"},{"v":"4"},{"v":"3"}]},
                                                     {"c":[{"v":"8\/2012"},{"v":31},{"v":"2"},{"v":"5"},{"v":0}]},
                                                     {"c":[{"v":"9\/2012"},{"v":47},{"v":"2"},{"v":"1"},{"v":"1"}]},
                                                     {"c":[{"v":"10\/2012"},{"v":67},{"v":0},{"v":"5"},{"v":"1"}]},
                                                     {"c":[{"v":"11\/2012"},{"v":38},{"v":"1"},{"v":"4"},{"v":0}]},
                                                     {"c":[{"v":"12\/2012"},{"v":14},{"v":"1"},{"v":"1"},{"v":"1"}]}
                                                    ]});       


// Create and draw the visualization.
new google.visualization.BarChart(document.getElementById('visualization')).
  draw(data,
       {title:"Yearly Coffee Consumption by Country",
        width:1000, height:400,
        vAxis: {title: "Year"},
        hAxis: {title: "Cups"}}
  );
}

我希望有人可以帮助我...

谢谢!

4

1 回答 1

0

我只是遇到了同样的问题。解决方法是,数值不能在引号之间,否则“3”+“4”会变成 34 而不是 7。

如果那里有数字值,只需删除 " 标记。干杯,格雷格

更新:如果您也使用 'f:' 值,您将需要再次使用引号,否则鼠标悬停可能无法在图表上使用。

{"c":[{"v":"12\/2012"},{"v":14, "f":"14"},{"v":1, "f":"1"},{"v":1, "f":"1"},{"v":1, "f":"1"}]}
于 2013-03-26T15:38:08.023 回答