如何从使用Google Charts生成的组合图表中删除网格线

时间:2016-04-20 10:14:51

标签: javascript charts google-chartwrapper

我有以下代码生成使用Javascript代码生成的组合图:

<script type="text/javascript">
  google.setOnLoadCallback(drawVisualization);


  function drawVisualization() {
    // Some raw data (not necessarily accurate)
    var data = google.visualization.arrayToDataTable([
     ['Days', 'Seat Utilization', 'RevPash'],
     ['Monday',  .61,      34.33],
     ['Tuesday',  .59,      33.15],
     ['Wednesday',  .64,      34.83],
     ['Thursday',  .62,      32.85],
     ['Friday',  .73,      37.30],
     ['Saturday',  .89,      49.76],
     ['Sunday',  .87,      45.99]
  ]);
        var view = new google.visualization.DataView(data);
            view.setColumns([0, 1,
                            { //calc: "stringify",
                                sourceColumn: 1,
                                type: "number",
                                role: "annotation" },2]);
var options = {
  title : '',
  vAxes: {0: {title: "",titleTextStyle: {italic: false},gridlines: { color: 'transparent'}}, 1: {title: "",titleTextStyle: {italic: false},format: 'percent'},gridlines: { color: 'transparent'} },
  hAxis: {title: 'Days',titleTextStyle: {italic: false},gridlines: { color: 'transparent'},textStyle : {fontSize: 9 } },
  chartArea: {'width': '90%', 'height': '80%'},
  seriesType: 'bars',
  series: {1: {type: 'area'}},
  legend: { position: 'top' },
  height: 300,

  series: {
        1:{ type: "area", targetAxisIndex: 0, color:'#EA922B' },
        0:{ type: "bars", targetAxisIndex: 1, color:'#20488D' },
        2:{ type: "bars", targetAxisIndex: 1, color:'#94CAFC' },


    }
};

var chart = new google.visualization.ComboChart(document.getElementById('chart_combo'));
chart.draw(view, options);
 }
</script>

图表如下所示:

enter image description here

我该怎么做才能删除网格线?我尝试过使网格线透明的选项,但由于某种原因它不起作用。我无法理解我如何删除网格线。请帮忙

2 个答案:

答案 0 :(得分:1)

问题是vAxes gridlines1定义中的拼写错误...

gridlines: {color: 'transparent'}
在对象花括号

之外定义

从...改变 vAxes: {0: {title: "",titleTextStyle: {italic: false},gridlines: { color: 'transparent'}}, 1: {title: "",titleTextStyle: {italic: false},format: 'percent'},gridlines: { color: 'transparent'} }

为...
vAxes: {0: {title: "",titleTextStyle: {italic: false},gridlines: { color: 'transparent'}}, 1: {title: "",titleTextStyle: {italic: false},format: 'percent',gridlines: { color: 'transparent'}} }

答案 1 :(得分:0)

vAxis: { gridlines: {color: 'none'} }

[eidt] 适用于这个谷歌文档开发人员wiki链接的小提琴:https://developers.google.com/chart/interactive/docs/datesandtimes#formatting-axis-gridline-and-tick-labels