javascript - Google 气泡图自定义工具提示列不呈现

标签 javascript charts tooltip google-visualization

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

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

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

最佳答案

我最终制作了一个运行良好的自定义工具提示弹出窗口。

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

<div id="bubble_chart_div"></div>

然后我使用了下面的 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);

关于javascript - Google 气泡图自定义工具提示列不呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14566766/

相关文章:

reactjs - 在 ReactJS 中的图表内添加数据标签不起作用?

tooltip - 具有多个叠加层的 GMap.Net 工具提示

javascript - Angular Directive(指令)/模板中的递归

javascript - Webix 日历插件禁用 Android 上的滚动和滑动

javascript - Highcharts.js - 仅轴的背景颜色

objective-c - 我可以在 NSView 的工具提示内添加超链接吗?

javascript - 获取 ListView 中任何选项的工具提示

javascript - Onclick javascript 函数在第一次点击时不起作用

javascript - 向超出 3 行的内容添加省略号

charts - 在主测量轴上设置最大值