简体   繁体   English

工具提示自定义不适用于Google图表

[英]Tooltip customization not working for Google Charts

I'm trying to create custom tooltips for a Google Charts timeline chart, but I can't get my custom string to show up. 我正在尝试为Google Charts时间线图表创建自定义工具提示,但无法显示自定义字符串。 The chart still displays the default tooltip. 该图表仍显示默认工具提示。

  google.charts.load('current', {'packages':['timeline']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'Team');
  data.addColumn('date', 'Season Start Date');
  data.addColumn('date', 'Season End Date');
  data.addColumn({type: 'string', role: 'tooltip'});

  data.addRows([
    ['Baltimore Ravens',     new Date(2000, 8, 5), new Date(2001, 1, 5), 'my tooltip'],
    ['New England Patriots', new Date(2001, 8, 5), new Date(2002, 1, 5), 'my tooltip'],
  ]);

  var options = {
    height: 450,
    timeline: {
      groupByRowLabel: true
    }
  };

  var chart = new google.visualization.Timeline(document.getElementById('chart_div'));

  chart.draw(data, options);
}

Here is the Google Charts documentation: https://developers.google.com/chart/interactive/docs/customizing_tooltip_content 这是Google图表文档: https : //developers.google.com/chart/interactive/docs/customizing_tooltip_content

JSFiddle: https://jsfiddle.net/nt12ev9h/ JSFiddle: https ://jsfiddle.net/nt12ev9h/

What am I doing wrong? 我究竟做错了什么?

As mentioned by WhiteHat, my columns were out of order. 正如WhiteHat所提到的,我的专栏是混乱的。

function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'Team');
  data.addColumn('string', 'Time');
  data.addColumn({type: 'string', role: 'tooltip'});
  data.addColumn('date', 'Season Start Date');
  data.addColumn('date', 'Season End Date');

  data.addRows([
    ['Baltimore Ravens',  '', 'my tooltip',   new Date(2000, 8, 5), new Date(2001, 1, 5)],
    ['New England Patriots', '', 'my tooltip', new Date(2001, 8, 5), new Date(2002, 1, 5)],
  ]);

Updated JSFiddle: https://jsfiddle.net/nt12ev9h/2/ 更新的JSFiddle: https ://jsfiddle.net/nt12ev9h/2/

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

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