jquery - 使用 Google Charts 在堆积柱形图中显示 Y 轴

标签 jquery charts google-visualization stacked-chart yaxis

我正在使用谷歌图表来显示我的堆积图表。我的x轴是数字,y轴也是数字。我得到一条黑线作为 x 轴。但 y 轴丢失了。不显示。

我尝试了下面提到的属性,但它不起作用:

 vAxis: {
      baseline: 0,
    }

需要设置什么属性才能显示 Y 轴。

Fiddle

最佳答案

放置在 x 轴上的 View 窗口隐藏/覆盖基线...

hAxis: {
  viewWindow: {
    min: min,
    max: max
  }
  ...

将最小值更改为零,允许出现基线...

var min = 0;
var max = data.getColumnRange(0).max;

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

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ['Machine', '', {
      role: 'style'
    }, '', {
      role: 'style'
    }, '', {
      role: 'style'
    }, '', {
      role: 'style'
    }, ''],
    [0.5, null, null, null, null, null, null, null, null, 0.067],
    [1, 0.05, "#808080", 0.0775, "#C71585", 0.069, "#FFC0CB", 0.05, "Blue", 0.067],
    [2, 0.05, "Yellow", 0.0775, "Pink", 0.069, "#808080", 0.05, "Green", 0.067],
    [2.5, null, null, null, null, null, null, null, null, 0.067]
  ]);

  var min = 0;
  var max = data.getColumnRange(0).max;

  var options = {
    width: 500,
    height: 500,
    legend: {
      position: 'none',
      maxLines: 6,
      textStyle: {
        color: 'black',
        fontSize: 10
      }
    },
    isStacked: true,
    seriesType: 'bars',
    series: {
      4: {
        type: "line",
        color: '#FF0000',
        visibleInLegend: false
      }

    },
    hAxis: {
      ticks: [{
        "v": 1,
        "f": "M1"
      }, {
        "v": 2,
        "f": "M2"
      }],
      viewWindow: {
        min: min,
        max: max
      }
    }
  };

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

关于jquery - 使用 Google Charts 在堆积柱形图中显示 Y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48655494/

相关文章:

jquery - 通过 ajax 调用加载 google 图表

javascript - 如何更改 Google Visualization API GeoChart 中的工具提示字体

javascript - 谷歌图表 : Plotting mutiple "Y" values on same "X" value

javascript - 停止交互(单击、拖动)在控件上传播(传单)

javascript - 为什么我的 cookie 没有更新?

javascript - canvas js 日期在 x 轴上重复

javascript - 使用 Google Chart 从数据集生成多个圆环图

ios - 如何使用 “Charts” 创建空标签?

javascript - jquery获取固定宽度内的段落宽度

jquery - 检查 jquery.validate 中的字符串