简体   繁体   English

谷歌图表:修改toopl提示

[英]Google chart : modify toopl tip

I have a joint chart using google chart API.我有一个使用谷歌图表 API 的联合图表。 Here i want to update the tool tip of the chart.在这里我想更新图表的工具提示。

As there is a lot of overlap in these charts i might not be able to actually hover over each discrete point and see data.由于这些图表中有很多重叠,我可能无法实际将鼠标悬停在每个离散点上并查看数据。

you can use a DataView to provide a calculated column您可以使用DataView来提供计算列
which builds the tooltip for that row为该行构建工具提示

see following snippet...看下面的片段...

var dataView = new google.visualization.DataView(joinedData);
dataView.setColumns([0, 1, {
  calc: function (dt, row) {
    return getTooltip(dt, row);
  },
  role: 'tooltip',
  type: 'string',
  p: {
    html: true
  }
}, 2, {
  calc: function (dt, row) {
    return getTooltip(dt, row);
  },
  role: 'tooltip',
  type: 'string',
  p: {
    html: true
  }
}]);

function getTooltip(dt, row) {
  var tooltip = '<div class="tooltip">';
  tooltip += '<div>' + dt.getFormattedValue(row, 0) + '</div>';

  tooltip += '<div>' + dt.getColumnLabel(1) + '</div>';
  if (dt.getValue(row, 1) === null) {
    tooltip += '<div>' + dt.getFormattedValue(row + 1, 1) + '</div>';
  } else {
    tooltip += '<div>' + dt.getFormattedValue(row, 1) + '</div>';
  }

  tooltip += '<div>' + dt.getColumnLabel(2) + '</div>';
  if (dt.getValue(row, 2) === null) {
    if (row > 0) {
      tooltip += '<div>' + dt.getFormattedValue(row - 1, 2) + '</div>';
    }
  } else {
    tooltip += '<div>' + dt.getFormattedValue(row, 2) + '</div>';
  }

  tooltip += '</div>';
  return tooltip;
}

full snippet --> http://jsfiddle.net/sqdfrf8f/1/完整片段--> http://jsfiddle.net/sqdfrf8f/1/


note: there is some sort of bug,注意:有某种错误,
in that the chart will not respect column properties on data views因为图表不会尊重数据视图上的列属性
so the html property doesn't get set所以没有设置html属性
the work around is to use data view method --> toDataTable()解决方法是使用数据视图方法 --> toDataTable()

also: need to use updated library for google charts, see --> update library loader code另外:需要为谷歌图表使用更新的库,请参阅 --> 更新库加载器代码

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

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