谷歌图表:多条线路与自定义工具提示

5

我有一个带有多条线的Google LineChart。这些点没有共享相同的X值,因此我必须以某种特定的方式格式化我的数据才能使它正常工作:

var data = google.visualization.arrayToDataTable([
        ["Y", "Your X & Y", "Product 1", "Product 2", "Product 3"],
        [419, 589, null, null, null],
        [386, null, 504, null, null],
        [386, null, 526, null, null],
        [387, null, 543, null, null],
        [395, null, 564, null, null],
        [402, null, 591, null, null],
        [408, null, 612, null, null],
        [378, null, null, 501, null],
        [398, null, null, null, 600],
        [460, null, null, null, 500]
    ]);

现在我想给这些线条添加自定义工具提示,我尝试添加一个额外的列并将角色设置为tooltip,但这只影响第一条线。请查看包含和不包含工具提示的两个图表:http://jsfiddle.net/TD92C/8/。如何为所有线条添加自定义工具提示?谢谢。

SOLVED: http://jsfiddle.net/asgallant/TD92C/14/


感谢您分享您的解决方案,先生。 - Lorenzo Marcon
1个回答

0

你必须像这样定义你的变量

var data = google.visualization.arrayToDataTable([
//Columns

    ["Y", //Name  of the X-axis marker
    "Your X & Y",{type: 'string', role: 'tooltip'},
    "Product 1",{type: 'string', role: 'tooltip'},
    "Product 2",{type: 'string', role: 'tooltip'},
    "Product 3",{type: 'string', role: 'tooltip'},],
//Rows
//Add tooltip column after every value in each row

    [419,589,"tooltip info about your x & y",null,'',null,'',null,''],
    [386,null,'',504,'','Custom Tooltip',null,'',null,''],
    [386,null,'',526,'Custom Tooltip',null,'',null,''],
    [387,null,'',543,'Custom Tooltip',null,'',null,''],
    [378,null,'',null,'',501,'Custom Tooltip',null,''],
    [383,null,'',null,'',511,'Custom Tooltip',null,''],
    [368,null,'',null,'',null,'',526,'Custom Tooltip'],
    [373,null,'',null,'',null,'',547,'Custom Tooltip'],
]);

Fiddle 数据看起来不同,但如果您将第一个元素更正为一个字符串,该字符串与第一列索引中显示的列完全相同,则它将是正确的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接