gpt4 book ai didi

google-visualization - Google可视化API-堆叠条形图-自定义工具提示

转载 作者:行者123 更新时间:2023-12-03 22:24:26 25 4
gpt4 key购买 nike

我一直在尝试获取堆积条形图的自定义工具提示。

var data = new google.visualization.DataTable();
data.addColumn('string', 'Units');
data.addColumn('number', '1');
data.addColumn('number', '2');
data.addColumn('number', '3');
data.addColumn('number', '4');

_1 = 0.123
_2 = 0.23
_3 = 0.3
_4 = 0

data.addRow([_units, _1, _2, _3, _4,]);

var options = {
isStacked: true,
height: 150,
chartArea: { height: 50 },
legend: { position: 'top' },
};

bchart = new google.visualization.BarChart(bcontainer);
bchart.draw(data, options);

然后我的问题是如何为以下各项分别创建一个工具提示:_1,_2,_3,_4?

谢谢

最佳答案

Google文档的DataTable Roles中对此进行了介绍。

在“条形图”文档中,它说明了该图表可使用的角色here

您需要做的是在添加了{role:tooltip}的情况下向数据中添加其他列,并在该列中显示您希望工具提示说的内容。

例如:

  var data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Sales');
data.addColumn({type: 'string', role: 'tooltip'});
data.addColumn('number', 'Expenses');
data.addColumn({type: 'string', role: 'tooltip'});
data.addRows([
['2004', 1000, '1M$ sales in 2004', 400, '$0.4M expenses in 2004'],
['2005', 1170, '1.17M$ sales in 2005', 460, '$0.46M expenses in 2005'],
['2006', 660, '.66$ sales in 2006', 1120, '$1.12M expenses in 2006'],
['2007', 1030, '1.03M$ sales in 2007', 540, '$0.54M expenses in 2007']
]);

最终代码如下所示:
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Sales');
data.addColumn({type: 'string', role: 'tooltip'});
data.addColumn('number', 'Expenses');
data.addColumn({type: 'string', role: 'tooltip'});
data.addRows([
['2004', 1000, '1M$ sales in 2004', 400, '$0.4M expenses in 2004'],
['2005', 1170, '1.17M$ sales in 2005', 460, '$0.46M expenses in 2005'],
['2006', 660, '.66$ sales in 2006', 1120, '$1.12M expenses in 2006'],
['2007', 1030, '1.03M$ sales in 2007', 540, '$0.54M expenses in 2007']
]);

// Create and draw the visualization.
new google.visualization.BarChart(document.getElementById('visualization')).
draw(data,
{title:"Yearly Coffee Consumption by Country",
isStacked: true,
width:600, height:400,
vAxis: {title: "Year"},
hAxis: {title: "Sales"}}
);
}

查看示例 here

关于google-visualization - Google可视化API-堆叠条形图-自定义工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14263051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com