如何从谷歌图表中删除 y 轴值

问题描述 投票:0回答:2

我正在使用谷歌图表。

在附图中,我不想显示 100、50、0、-50、-100 数字。但我确实希望显示满意度标签。有谁知道如何在谷歌图表中实现这一点? vAxis 上有选项吗?

另一个(不太重要)问题是我只想要 100、0 和 -100 处的网格线。其他 6 个我不要了。

我目前设置了以下选项...

var options = {
    chartArea: { width: '80%' },
    colors: ['#00ff00', '#ff0000'],
    vAxis: {
        title: 'Satisfaction',
        maxValue: 100,
        minValue: -100,
        gridlines: { count: 2 }
    },
    legend: { position: 'bottom' }
};

谢谢。

charts google-visualization
2个回答
4
投票

使用以下 vAxis 选项...

textPosition: 'none'

请参阅以下工作片段...

google.charts.load('current', {
  packages: ['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ['x', 'y0', 'y1', 'y2'],
    [0, 10, 12, 18],
    [2, 16, 18, 19],
    [4, 18, 19, 24],
    [6, 26, 28, 22],
    [8, 13, 15, 21],
    [10, 32, 31, 33]
  ]);

  var options = {
    chartArea: { width: '80%' },
    colors: ['#00ff00', '#ff0000'],
    vAxis: {
      textPosition: 'none',
      title: 'Satisfaction',
      maxValue: 100,
      minValue: -100,
      gridlines: { count: 2 }
    },
    legend: { position: 'bottom' }
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart'));
  chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>


0
投票
  1. 在图表配置中选择“网格线和刻度线”。
  2. 在第一个下拉列表中,根据需要选择垂直或水平轴。
  3. 在“主要间距类型”下拉列表中选择“计数”。
  4. 在“主要计数”下拉列表中选择“无”。

这将使所选轴上的值消失。

© www.soinside.com 2019 - 2024. All rights reserved.