谷歌图表垂直组合vhaxis

问题描述 投票:1回答:1

我有一个Google Charts组合图,我已经配置了图表的垂直位置。

我无法为顶部和底部的数值添加标签,也无法显示顶部的数值。

我怎样才能显示顶部和底部的数值,同时添加一个标签,顶部数值的标签是 "百分比",底部数值的标签是 "美元"。

这是我的实际代码。

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'percentage', 'total'],
      ['2004/05',  165,      938,         522,             998,           45,      614.6],
      ['2005/06',  135,      1120,        599,             1268,          88,      682],
      ['2006/07',  157,      1167,        587,             807,           97,      623],
      ['2007/08',  139,      1110,        615,             968,           15,      609.4],
      ['2008/09',  136,      691,         629,             1026,          66,      569.6]
    ]);

    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
    chart.draw(data, {
    legend: {
        position: 'bottom',
        alignment: 'left'        
      },
      title : 'material production',
      vAxis: {},
      hAxis: {},
      height: 420,
      orientation: 'vertical',
      seriesType: 'bars',
      series: {
       0: {
          pointSize: 5,
          type: 'bars',
        },
        1: {
          pointSize: 5,
          type: 'bars'
        },
         2: {
          pointSize: 5,
          type: 'bars'
        },
        3: {
          pointSize: 5,
          type: 'bars'
        },
        4: {
          pointSize: 5,
          type: 'line'
        },
        5: {
          pointSize: 5,
          type: 'line'
        }
      }
    });
  },
  packages: ['corechart']
});

我有这个jsfiddle,我在这里测试我所需要的东西。https:/jsfiddle.netcruano23gpsa9Lo2

javascript charts google-visualization
1个回答
0
投票

你是想添加轴标题吗?

  vAxis: {title: 'Percentage'},
  hAxis: {title: 'USD'},

请看以下工作片段...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'percentage', 'total'],
      ['2004/05',  165,      938,         522,             998,           45,      614.6],
      ['2005/06',  135,      1120,        599,             1268,          88,      682],
      ['2006/07',  157,      1167,        587,             807,           97,      623],
      ['2007/08',  139,      1110,        615,             968,           15,      609.4],
      ['2008/09',  136,      691,         629,             1026,          66,      569.6]
    ]);

    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
    chart.draw(data, {
    legend: {
        position: 'bottom',
        alignment: 'left'        
      },
      title : 'material production',
      vAxis: {title: 'Percentage'},
      hAxis: {title: 'USD'},
      height: 420,
      orientation: 'vertical',
      seriesType: 'bars',
      series: {
       0: {
          pointSize: 5,
          type: 'bars',
        },
        1: {
          pointSize: 5,
          type: 'bars'
        },
         2: {
          pointSize: 5,
          type: 'bars'
        },
        3: {
          pointSize: 5,
          type: 'bars'
        },
        4: {
          pointSize: 5,
          type: 'line'
        },
        5: {
          pointSize: 5,
          type: 'line'
        }
      }
    });
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
© www.soinside.com 2019 - 2024. All rights reserved.