谷歌图表 - 具有相同日期不同年份的折线图

Google Charts - line chart with same date different year

本文关键字:日期 同年 折线图 谷歌      更新时间:2023-09-26

我想比较相同日期但不同年份的数据。

例如,对于 1 月 1 日的日期,我想在同一图表上显示 2016 年和 2015 年的数据,x 轴上的相同位置,但不同的折线系列。

这可能吗?

这是图表的一个例子,我想你描述的是......

google.charts.load('current', {
  callback: function () {
    var data = new google.visualization.DataTable();
    data.addColumn('date', 'Date');
    data.addColumn('number', '2005');
    data.addColumn('number', '2006');
    data.addRows([
       [new Date('01/01/2016'), 200, 210],
       [new Date('01/02/2016'), 190, 220],
       [new Date('01/03/2016'), 205, 200],
       [new Date('01/04/2016'), 220, 230],
       [new Date('01/05/2016'), 212, 210],
       [new Date('01/06/2016'), 185, 193],
       [new Date('01/07/2016'), 196, 207]
    ]);
    var options = {
      height: 400
    };
    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>