我正在尝试向气泡图添加自定义工具提示,以替换默认的工具提示。我遵循了文档站点(here)的说明,使用role: 'tooltip'向DataTable中添加了一个新的string列。但是,您可以在下面的JS fiddle示例中看到,自定义工具提示内容不会呈现。图表仍显示默认工具提示。
有人知道我还需要做什么才能让这个自定义工具提示内容显示出来吗?
发布于 2013-01-31 22:18:08
我最终制作了一个自定义的工具提示弹出窗口,效果很好。
假设气泡图的div定义如下:
<div id="bubble_chart_div"></div>然后我使用了下面的JavaScript。请注意,我遗漏了关于如何设置google图表数据和加载google图表包的内容。这段代码只是展示了如何让你的自定义工具弹出窗口。
var mouseX;
var mouseY;
$(document).mousemove( function(e) {
mouseX = e.pageX;
mouseY = e.pageY;
});
/*
*
*instantiate and render the chart to the screen
*
*/
var bubble_chart = new google.visualization.BubbleChart(document.getElementById('bubble_chart_div'));
bubble_chart.draw(customer_product_grid_data_table, options);
/*
* These functions handle the custom tooltip display
*/
function handler1(e){
var x = mouseX;
var y = mouseY - 130;
var a = 1;
var b = 2;
$('#custom_tooltip').html('<div>Value of A is'+a+' and value of B is'+b+'</div>').css({'top':y,'left':x}).fadeIn('slow');
}
function handler2(e){
$('#custom_tooltip').fadeOut('fast');
}
/*
* Attach the functions that handle the tool-tip pop-up
* handler1 is called when the mouse moves into the bubble, and handler 2 is called when mouse moves out of bubble
*/
google.visualization.events.addListener(bubble_chart, 'onmouseover', handler1);
google.visualization.events.addListener(bubble_chart, 'onmouseout', handler2);发布于 2013-01-30 10:04:11
如帮助文档底部所述:
目前,以下图表类型支持HTML工具提示:
不幸的是,气泡图不包括在内,因此您不能向它们添加自定义html工具提示。如果你愿意,你可以编写一个自定义的javascript来创建工具提示,但是你不能使用现有的功能来做你想做的事情。
https://stackoverflow.com/questions/14566766
复制相似问题