简体   繁体   English

如何隐藏谷歌地理标志中的工具提示标题(并在工具提示中显示其他信息)

[英]How to hide tooltip title in google geocharts (and show other info in the tooltip)

问题:如果您在Google地理标记中启用工具提示,则无法更改工具提示标题,这是您传递给Google图表绘制方法的第一列。

Instead of the CSS above to hide the title, you can set the showTitle option for the tooltip to false 您可以将工具提示的showTitle选项设置为false,而不是上面的CSS来隐藏标题

tooltip: {
        isHtml: true,
        showTitle: false
    }

Then you can use HTML markup in your tooltip to display the tooltip exactly the way you want. 然后,您可以在工具提示中使用HTML标记,以完全按照您希望的方式显示工具提示。

In google geocharts if you enable the tooltip visualization, the title will be the first column of the data you passed to the google geochart.draw function. 在google geocharts中,如果启用工具提示可视化,则标题将是您传递给google geochart.draw函数的数据的第一列。

In my case for performance consideration I found better to pass to google the ISO3166 nation 2 character code, it's resolved immediately, if you use the extended name it's not recognized immediately and it left some grey areas for some seconds. 在我的性能考虑的情况下,我发现更好地传递谷歌ISO3166国家2字符代码,它立即解决,如果你使用扩展名称,它不会立即被识别,它留下一些灰色区域几秒钟。

Unfortunately after this choice, the tooltip title shows the 2 letter nation iso code, but I need to show another title. 不幸的是,在这个选择之后,工具提示标题显示了2个字母的国家iso代码,但我需要显示另一个标题。

I created a json array built this way: 我用这种方式创建了一个json数组:

var arCustomersDataByNation = [['Country', 'MyNumericData','Tooltip'],['RU',4,'My beautiful tooltip'],['AE',3,'NewTooltipTitle3'],['AF',1,'NewTooltipTitle4']...];

Added the data to a google dataTable : 将数据添加到Google dataTable:

    var data = new google.visualization.DataTable();

    data.addColumn('string', 'Country');
    data.addColumn('number', 'MyNumericData');
    data.addColumn({type:'string', role:'tooltip'});

    for(var i = 1; i < arCustomersDataByNation.length; i++){
        data.addRows([[arCustomersDataByNation[i][0],arCustomersDataByNation[i][1],arCustomersDataByNation[i][2]]]);
    }

and defined the google chart options, the "isHtml: true" option is fundamental, is the only way to hack via CSS the geochart tooltip: 并定义了谷歌图表选项,“isHtml:true”选项是基础,是通过CSS攻击geochart工具提示的唯一方法:

var arSubCColors = ['#ffffff','#99E6FF','#70DBFF','#1FC7FF','#00B4F1'];
var zoom_0_options = {
    backgroundColor: {fill:'#f2f2f2',stroke:'#FFFFFF' ,strokeWidth:0 },
    colorAxis:  {minValue:0,maxValue:4,colors: arSubCColors},
    datalessRegionColor: '#ccc',
    displayMode: 'regions',
    enableRegionInteractivity: 'true',
    keepAspectRatio: true,
    legend: 'none',
    region:'world',
    resolution: 'countries',
    sizeAxis: {minValue: 1, maxValue:1,minSize:10,  maxSize: 10},
    tooltip : {textStyle: {color: '#666'}, showColorCode: true, isHtml: true}
};

Afyter this some CSS, the ".google-visualization-tooltip-item:first-child" rule hides the bold default title: 除了这个CSS之外,“。google-visualization-tooltip-item:first-child”规则隐藏了粗体默认标题:

.google-visualization-tooltip{
        border: 0px!important;
        height : 30px!important;
        list-style: none!important;
    }
    .google-visualization-tooltip-item
    {
        list-style: none!important;
        position: relative;
        top: -3px;
        color: #707173!important;
        font-weight: bold!important;
    }
    .google-visualization-tooltip-item-list .google-visualization-tooltip-item:first-child 
    {
        display: none; 
    }

And here is the result: 这是结果:

在此输入图像描述

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

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