Google 图表 - 堆积柱形图的趋势线

Google Charts - Trendline for Stacked Column Chart

我的问题是关于 Google 图表 API 的堆积柱形条形图。

我正试图从中得出一条全球趋势线。

<script type="text/javascript">
 google.charts.load("current", {"packages":["corechart"]});
 google.charts.setOnLoadCallback(drawVisualization);
 function drawVisualization() {
 var data = google.visualization.arrayToDataTable([['Month', 'OK', 'KO', 'Estimation'],[ '2016/08', 1990, 49, null ],[ '2016/09', 6892, 97, null ],[ '2016/10', 6018, 0, null ],[ '2016/11', 7329, 146, null ],[ '2016/12', 3059, 97, 1827 ]]);
 var options = {
  isStacked: true,
  seriesType: "bars",
  legend: "none",
  hAxis:{ textPosition: "none" },
  vAxis: { viewWindow: { min: 0, max: 8000 } },
  trendlines: { 0: {} }
 };
 var chart = new google.visualization.ComboChart(document.getElementById("bar"));
 chart.draw(data, options);
 }
 </script>

当我添加 trendlines: { 0: {} }, 时,我没有得到任何结果。

我在参考指南上没有找到任何内容。可能没有实现,或者我做错了?

虽然文档中没有提到,trendlines 仅在 Continuous x 轴

上受支持

这意味着第一列的值应该是日期、数字等...

字符串值导致 离散

参见discrete vs continuous...

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

第一列使用 DataView 转换为实际日期,这使 trendlines...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Month', 'OK', 'KO', 'Estimation'],
      ['2016/08', 1990, 49, null],
      ['2016/09', 6892, 97, null],
      ['2016/10', 6018, 0, null],
      ['2016/11', 7329, 146, null],
      ['2016/12', 3059, 97, 1827]
    ]);

    var view = new google.visualization.DataView(data);
    view.setColumns([{
      calc: function (dt, row) {
        var dateParts = dt.getValue(row, 0).split('/');
        return new Date(parseInt(dateParts[0]), parseInt(dateParts[1]) - 1, 1);
      },
      type: 'date',
      label: data.getColumnLabel(0)
    }, 1, 2, 3]);

    var options = {
      isStacked: true,
      seriesType: 'bars',
      legend: 'none',
      hAxis: {
        textPosition: 'none'
      },
      vAxis: {
        viewWindow: {
          min: 0,
          max: 8000
        }
      },
      trendlines: {
        0: {}
      }
    };

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