堆叠条形图中的注释位置错误(Google 图表 API)

Wrong position of annotations in a stacked bar chart (Google Chart API)

我有一个带有注释的堆叠条形图,可以对值求和。注释总是在栏的末尾,但是当最后一个数据行 (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

找到解决方法...添加了一个名为 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