谷歌图表工具堆积图表

时间:2012-12-17 09:11:25

标签: graph charts

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

You can try it yourself on the Google playground with this code

(只需添加'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"}}
  );
}

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

谢谢!

1 个答案:

答案 0 :(得分: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"}]}