简体   繁体   English

Google图表-工具提示

[英]Google Charts - Tooltips

I am trying to add a tooltip to a Time chart, however am experiencing very strange results: 我正在尝试向时间表添加工具提示,但是却遇到了非常奇怪的结果:

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}});

Do some dynamic stuff here and loop through: 在这里做一些动态的事情并循环:

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

chart.draw(dataTable);

The chart populates perfectly, except NO tooltip! 图表填充完美,没有工具提示!

Anyone have any ideas? 有人有想法么? Attached is my result! 附件是我的结果!

Here is an image: 这是一张图片:

在此处输入图片说明

If you check on documentation, html tooltip for Timeline is not supported: 如果您查看文档,则不支持时间轴的html工具提示:

supported_charts support_charts

However, you could make a workaround using onmouseover event listener and setting the tooltip according to the e.row value. 但是,您可以使用onmouseover事件监听器并根据e.row值设置工具提示来e.row Here is a simple example: 这是一个简单的示例:

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);

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

change this: 改变这个:

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

it should be: 它应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM