2015-08-08 26 views
3

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

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 ...

回答

2

找到一个解决办法...添加新的数据列,这个名字总被具有相同的值作为注释:

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

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

动力版本,这需要对注释的最后一个数据行:

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

options["series"] = series; 

Demo and code at JSFiddle