堆积条形图中注释的位置错误(Google Chart API) [英] Wrong position of annotations in a stacked bar chart (Google Chart API)

查看:326
本文介绍了堆积条形图中注释的位置错误(Google Chart API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有注释的堆积条形图,它们将这些值相加。注释总是在栏的末尾,但是当最后一个数据行(I)没有值时,注释在开始,我不知道如何解决它。

  var dataArray = [
[Date,A,B,C,D,E ,F,G,H,I,{角色:'annotation'}],
[7.08.2015,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]
];



这会使Total栏透明,将它隐藏在图例中并让它从零点开始。



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

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

options [series] = series;

JSFiddle上的演示和代码


I have a stacked bar chart with annotations which sums the values. The annotations are always at the end of the bar, but when there isn't a value for the last data row (I) the annotation is at the beginning and I don't know how to fix it.

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

解决方案

Found a workaround ... added a new data column, with the name Total, is has the same value as the annotation:

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]
];

And added this to the options:

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

Demo and code at JSFiddle

This makes the Total bar transparent, hide it in the legends and let it start from the zero point.

Dynamic version which takes the last data row for the annotations:

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

options["series"] = series;

Demo and code at JSFiddle

这篇关于堆积条形图中注释的位置错误(Google Chart API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆