首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google气泡图自定义工具提示列不呈现

问Google气泡图自定义工具提示列不呈现
EN

Stack Overflow用户
提问于 2013-01-29 00:41:09
回答 2查看 2K关注 0票数 2

我正在尝试向气泡图添加自定义工具提示,以替换默认的工具提示。我遵循了文档站点(here)的说明,使用role: 'tooltip'向DataTable中添加了一个新的string列。但是,您可以在下面的JS fiddle示例中看到,自定义工具提示内容不会呈现。图表仍显示默认工具提示。

有人知道我还需要做什么才能让这个自定义工具提示内容显示出来吗?

http://jsfiddle.net/MPBmY/2/

EN

回答 2

Stack Overflow用户

发布于 2013-01-31 22:18:08

我最终制作了一个自定义的工具提示弹出窗口,效果很好。

假设气泡图的div定义如下:

代码语言:javascript
复制
<div id="bubble_chart_div"></div>

然后我使用了下面的JavaScript。请注意,我遗漏了关于如何设置google图表数据和加载google图表包的内容。这段代码只是展示了如何让你的自定义工具弹出窗口。

代码语言:javascript
复制
    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);
票数 2
EN

Stack Overflow用户

发布于 2013-01-30 10:04:11

如帮助文档底部所述:

目前,以下图表类型支持HTML工具提示:

  • AreaChart
  • BarChart
  • CandlestickChart
  • ColumnChart
  • ComboChart
  • LineChart
  • ScatterChart

不幸的是,气泡图不包括在内,因此您不能向它们添加自定义html工具提示。如果你愿意,你可以编写一个自定义的javascript来创建工具提示,但是你不能使用现有的功能来做你想做的事情。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14566766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档