0

我是谷歌图表的新手,似乎无法弄清楚我将如何做以下事情:

我想制作一个包含我的 xcord、ycord、legendlabel 的数据表。我正在尝试以下操作:

var data = google.visualization.arrayToDataTable([]);   

            data.addColumn("number","reps");
            data.addColumn("number","weight");
            data.addColumn("string","legendlabel")

            //data.addColumn("string","workoutname");

            data.addRows([[150, 10,"workoutA"],
                          [300, 2,"workoutB"],

                        ]);

但是,它显然不起作用,因为我们有两种不同的类型,数字和字符串。

有没有办法我可以指定xcord,ycord然后为这一点设置一个标签,然后如果有多个相同的标签,它会形成一个折线图?

提前谢谢各位!

4

1 回答 1

0

I there some reason you're initializing the empty data variable and then adding to it?

Why not do this:

var data = google.visualization.arrayToDataTable([
  ['legendlabel', 'Reps', 'Weight'],
  ['workoutA', 150, 10],
  ['workoutB', 300, 2]
]);

…which works in my test at the Google Code Playground.

Though, it probably doesn't display what you want, since you're comparing two scalars values of different scales (one is 2-10, one is 150-300). What sort of graph are you hoping to see?

This question may help you with dual y-axes: Can Google Charts support dual y-axis (v-axis)?

于 2012-08-07T02:04:10.230 回答