javascript - Google 图表 - 工具提示

标签 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

最佳答案

如果您查看文档,不支持时间轴的 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/

关于javascript - Google 图表 - 工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25244261/

相关文章:

css - 设置谷歌图表宽度

php - 根据用户检查复选框从数据库检索数据并显示在谷歌图表中

javascript - 单击模态窗口外部时重置 Bootstrap 模态

javascript - 将 GA 事件添加到可重用的 React 组件中

javascript - jQuery 在鼠标移出时处理 hover() 和未完成的动画

jquery - 使用 jQuery 限制特殊字符

javascript - 如何使用 CSS/jQuery 在另一个之上创建多个 div?

PHP 错误 : Notice: Undefined variable

jquery - 通过 jQuery/ajax+JSON 将 ID 和字符串数组传递给 Spring MVC

javascript - 将服务器端谷歌图表生成为图像