2014-10-30 39 views
1

从这JSFiddle开始,你会注意到每个系列有一组y标签,这是预期的这种类型的情节,但是,我不知道不要他们,或者至少只想要他们中的一个。我怎样才能隐藏右边的y标签,或者至少是所有的y标签?谷歌图表选项隐藏y标签和注释

此外,是否有一种简单的方法来显示数据值作为每个栏节的注释?

google.load('visualization', '1.1', { 
    'packages': ['bar'] 
}); 
google.setOnLoadCallback(drawStuff); 

function drawStuff() { 
    var data = google.visualization.arrayToDataTable([ 
     ['X-Title', 'Blue 1', 'Blue 2', 'Red 1', 'Red 2', 'Yellow 1', 'Yellow 2'], 
     ['2001', 321, 621, 816, 319, 125, 175], 
     ['2002', 163, 231, 539, 594, 225, 300], 
     ['2003', 125, 819, 123, 578, 100, 200], 
     ['2004', 197, 536, 613, 298, 25, 150] 
    ]); 

    // Set chart options 
    var options = { 
     isStacked: true, 
     width: 800, 
     height: 600, 
     chart: { 
      title: 'Year-by-year comparison', 
      subtitle: 'This data is not real' 
     }, 
     vAxis: { 
      viewWindow: { 
       min: 0, 
       max: 1200 
      } 
     }, 
     series: { 
      0: { 
       targetAxisIndex: 0 
      }, 
      1: { 
       targetAxisIndex: 0 
      }, 
      2: { 
       targetAxisIndex: 1 
      }, 
      3: { 
       targetAxisIndex: 1 
      }, 
      4: { 
       targetAxisIndex: 2 
      }, 
      5: { 
       targetAxisIndex: 2 
      } 
     } 
    }; 

    // Instantiate and draw our chart, passing in some options. 
    var chart_div = document.getElementById('chart_div'); 
    var chart = new google.charts.Bar(chart_div);  
    chart.draw(data, google.charts.Bar.convertOptions(options)); 
}; 

回答

0

对于轴的操作,你需要使用vAxes选项:

vAxes:{ 
     1:{textStyle:{color:'none'}}, // this will hide the first on the right 
     2:{textStyle:{color:'none'}}, // this will hide the second on the right 
    } 
+0

这确实让文字消失,但空间仍然浪费了他们在哪里,如果我增加更多系列,大部分空间将被浪费。 – steveo225 2014-10-30 18:53:31

+0

那么,还有另一种方式做'textPosition:'none'',但它似乎仍然不能用于材质图表:( – juvian 2014-10-30 18:59:38

+0

是的,我一直无法找到任何适用于它们的东西 – steveo225 2014-10-30 19:04:32