Google绘制了具有非均匀x轴值的折线图

时间:2014-06-30 12:00:45

标签: data-structures charts google-visualization linechart

我需要制作一个谷歌折线图,学生可以回答最多五个问题,其值从1到100。

折线图应该在y轴上有答案,答案的时间和日期应该在x轴上。

学生同时回答所有问题。

每个学生每个答案应该有一行。

同一问题的行应该具有相同的颜色 - 即。如果有三个学生,每种颜色应该有三行,每个学生一行。

我的数据在PHP中被解析为json-string并加载到Google Charts之前就是这样的:

$testtable = array(
   'cols' => array(
       array('label' => 'Date', 'type' => 'datetime'),
       array('label' => 'Student', 'type' => 'string', 'role' => 'tooltip'),
       array('label' => 'Answer1', 'type' => 'number'),
       array('label' => 'Answer2', 'type' => 'number'),
       array('label' => 'Answer3', 'type' => 'number'),
       array('label' => 'Answer4', 'type' => 'number'),
       array('label' => 'Answer5', 'type' => 'number')
   ),
    'rows' => array(
        array('c' => array(
            array('v' => 'Date(2014,3,4,17,3,17)'),
            array('v' => 'elev1'),
            array('v' => 15),
            array('v' => 36),
            array('v' => 87),
            array('v' => 10),
            array('v' => 22)
        )),
        array('c' => array(
            array('v' => 'Date(2014,3,4,13,56,22)'),
            array('v' => 'elev2'),
            array('v' => 11),
            array('v' => 66),
            array('v' => 87),
            array('v' => 23),
            array('v' => 27)
        )),
        array('c' => array(
            array('v' => 'Date(2014,3,5,10,27,31)'),
            array('v' => 'elev1'),
            array('v' => 43),
            array('v' => 11),
            array('v' => 33),
            array('v' => 64),
            array('v' => 88)
        )),
        array('c' => array(
            array('v' => 'Date(2014,3,5,12,22,53)'),
            array('v' => 'elev2'),
            array('v' => 22),
            array('v' => 34),
            array('v' => 62),
            array('v' => 32),
            array('v' => 5)
        )),
    )
);

以下是我的想法: http://s21.postimg.org/p146t1dqf/chart.png

以下是我的图表目前的情况: http://s11.postimg.org/w6gvfa5n7/chart2.png

我非常确定我的数据结构错误,但我无法以正确的方式解决问题。如果有人可以提供帮助,我会非常高兴。

1 个答案:

答案 0 :(得分:0)

LineChart每行需要一个数据系列,因此如果每个问题每个学生需要一行,则每个问题每个学生需要一个数据系列(DataTable列)(因此,如果您有3个学生和5个问题,则需要15个数据系列)。使用colorsseries.<series index>.color选项为线条着色。

'cols' => array(
    array('label' => 'Date', 'type' => 'datetime'),
    array('label' => 'Student1 Answer1', 'type' => 'number'),
    array('label' => 'Student1 Answer2', 'type' => 'number'),
    array('label' => 'Student1 Answer3', 'type' => 'number'),
    array('label' => 'Student1 Answer4', 'type' => 'number'),
    array('label' => 'Student1 Answer5', 'type' => 'number'),
    array('label' => 'Student2 Answer1', 'type' => 'number'),
    array('label' => 'Student2 Answer2', 'type' => 'number'),
    array('label' => 'Student2 Answer3', 'type' => 'number'),
    array('label' => 'Student2 Answer4', 'type' => 'number'),
    array('label' => 'Student2 Answer5', 'type' => 'number'),
    array('label' => 'Student3 Answer1', 'type' => 'number'),
    array('label' => 'Student3 Answer2', 'type' => 'number'),
    array('label' => 'Student3 Answer3', 'type' => 'number'),
    array('label' => 'Student3 Answer4', 'type' => 'number'),
    array('label' => 'Student3 Answer5', 'type' => 'number')
    // etc...
)