google-visualization - 堆叠条形图中注释的错误位置(Google Chart API)

标签 google-visualization

我有一个带有注释的堆叠条形图,可以对值求和。注释总是在栏的末尾,但是当最后一个数据行 (I) 没有值时,注释在开头,我不知道如何修复它。

var dataArray = [
    ["Date", "A", "B", "C", "D", "E", "F", "G", "H", "I", {role: 'annotation'}],
    ["7.08.2015", 0, 0, 0, 3, 6, 1, 0, 0, 0, 10],
    ["6.08.2015", 0, 0, 0, 0, 4, 6, 1, 0, 7, 18],
    ["5.08.2015", 0, 0, 0, 2, 4, 0, 0, 0, 5, 11]
];

Demo and code at JSFiddle

Image of the problem ...

最佳答案

找到了解决方法...添加了一个新的数据列,名称为 Total,与注释具有相同的值:

var dataArray = [
    ["Date", "A", "B", "C", "D", "E", "F", "G", "H", "I", "Total", {role: 'annotation'}],
    ["7.08.2015", 0, 0, 0, 3, 6, 1, 0, 0, 0, 10, 10],
    ["6.08.2015", 0, 0, 0, 0, 4, 6, 1, 0, 7, 18, 18],
    ["5.08.2015", 0, 0, 0, 2, 4, 0, 0, 0, 5, 11, 11]
];

并将其添加到选项中:

var options = {
    ...
    series: {
        9: {
            color: 'transparent',
            type: "bar",
            targetAxisIndex: 1,
            visibleInLegend: false
        }
    }
};

Demo and code at JSFiddle

这使得总计栏透明,将其隐藏在图例中并让它从零点开始。

采用最后一行数据作为注释的动态版本:

var series = {};
series[data.getNumberOfColumns() - 3] = {
    color: 'transparent',
    type: "bar",
    targetAxisIndex: 1,
    visibleInLegend: false
};

options["series"] = series;

Demo and code at JSFiddle

关于google-visualization - 堆叠条形图中注释的错误位置(Google Chart API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31889316/

相关文章:

javascript - 谷歌地理图表设置标记显示模式与国家/地区的背景颜色

javascript - 显示 Google 图表的问题

android - 谷歌图表水平滚动

javascript - 谷歌图表 : Is it possible to have a pie chart substituting the dot in the scatterplot?

javascript - 无法使用 onclick 函数将选择标签上的值添加到谷歌图表数据表

javascript - 如何增加 Google 时间线图表的行高?

javascript - 阻止 Google 图表放大

javascript - Google 图表 - 第 138 行 loader.js 繁忙时出现错误

javascript - 在 HTML 页面顶部形成奇怪的空间

html - 中心对齐谷歌图表