【发布时间】:2015-04-19 03:25:27
【问题描述】:
我正在尝试将自定义工具提示添加到 Google 条形图,但我不知道如何执行此操作。 Google 提供了一个很好的教程(https://developers.google.com/chart/interactive/docs/customizing_tooltip_content),但它只讨论柱形图,而不是条形图。
我的代码如下所示:
<div id="top_x_div" style="width: 900px; height: 500px;"></div>
google.load("visualization", "1.1",{packages:["bar"]});
google.setOnLoadCallback(drawStuff0);
function drawStuff0() {
var data = new google.visualization.arrayToDataTable([$data]);
var options = {
title: 'Categories',
width: 900,
legend: { position: 'none' },
chart: { title: 'popularity by number of queries',
subtitle: 'Number of times a category was queried' },
bars: 'horizontal', // Required for Material Bar Charts.
axes: {
x: {
0: { side: 'top', label: 'Number of times a category was queried'} // Top x-axis.
}
},
bar: { groupWidth: "90%" }
};
var chart = new google.charts.Bar(document.getElementById('top_x_div0'));
// Convert the Classic options to Material options.
chart.draw(data, google.charts.Bar.convertOptions(options));
};
$data 只是一个包含图表行的 PHP 变量。
有人能解释一下如何在此图表中添加自定义工具提示吗? 我在网上到处寻找解决方案,但我一直找不到...
【问题讨论】:
标签: javascript charts google-visualization