【发布时间】:2023-03-25 18:53:02
【问题描述】:
我正在使用 Google Chart 的柱形图。该图表是一个堆积柱形图,为堆积柱形的每个数据点添加了注释。注释位于条形内部的顶部,但我希望它们位于条形内部的中心。我找到的最接近的解决方案是将非堆叠柱状谷歌图表的注释移动到底部here。
这个解决方案的问题是代码会寻找白色的注释并将它们移动到底部。我正在处理的图表有多种颜色的注释,并且该颜色的所有注释都移动到顶部而不是堆叠列子集的中心。
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Range', 'score range A',{role: 'style'},{ role: 'annotation' }, 'score range B',{role: 'style'},{ role: 'annotation' }, 'score range C', {role: 'style'},{ role: 'annotation' },'score range D', {role: 'style'},{ role: 'annotation' }],
['Range', 4,'#D7F0B4','0-4',6,'#00B050','5-10',9,'#92D050','11-19',6, '#AAE182','20-25']
]);
var options = {
vAxis:{ ticks: [0,4,10,19], viewWindow: { max: 25} },
isStacked: true,
title: 'Score',
legend: {position: 'none'}
};
var chart = new google.visualization.ColumnChart(document.getElementById('idealchartA'));
chart.draw(data, options);
}
@Whitehat 解决了上述问题,但是当我将另一列的某些注释值设为 null 时,定位被抛出。
这是我尝试添加的新数据系列
['Range', 4,'#D7F0B4','0-4',6,'#00B050','5-10',9,'#92D050','11-19',6, '#AAE182','20-25'], ['Yours', 4,'white; fill-opacity: 0',null,6, '#00B050',10, 9,'white; fill-opacity: 0',null,6,'white; fill-opacity: 0',null].
【问题讨论】:
标签: charts annotations position google-visualization stacked