Google图表 - 工具提示

时间:2014-08-11 13:19:38

标签: javascript jquery google-visualization

我正在尝试向时间图表添加工具提示,但是遇到了非常奇怪的结果:

var container = document.getElementById('example2.1');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();


dataTable.addColumn({ type: 'string', id: 'Name' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});

在这里做一些动态的东西并循环遍历:

dataTable.addRow([$(this).attr('ows_Title'),start,end,"Status: " + $(this).attr("ows_Status")]);

chart.draw(dataTable);

图表填充完整,除了没有工具提示!

有人有什么想法吗?附上是我的结果!

这是一张图片:

enter image description here

2 个答案:

答案 0 :(得分:5)

如果您查看文档,则不支持时间轴的html工具提示:

supported_charts

但是,您可以使用onmouseover事件侦听器并根据e.row值设置工具提示来制定变通方法。这是一个简单的例子:

function myHandler(e){
        if(e.row != null){
            $(".google-visualization-tooltip").html(dataTable.getValue(e.row,3)).css({width:"auto",height:"auto"});
        }        
    }

google.visualization.events.addListener(chart, 'onmouseover', myHandler);

完整示例:http://jsfiddle.net/s9g99pqk/1/

答案 1 :(得分:0)

改变这个:

dataTable.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});

它应该是:

dataTable.addColumn({type: 'string', role: 'tooltip', p: {'html': true}});
相关问题