charts.js 堆叠 y 轴

charts.js stacked y-Axis

我正在寻找一种 charts.js 的解决方案,它有 4 个堆叠的 y 轴,但只有一个 x 轴,就像我可以在 R 中使用绘图创建的那样。我找到了关于几个 y 的所有信息轴,但不堆叠。 预先感谢您的帮助。

只有当前的主代码才有可能,在 chart.js 的下一个版本之后,这将可以通过使用普通的 CDN 来实现

当前主分支代码示例:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange, Black"],
    datasets: [{
        label: 'Dataset 1',
        data: [10, 30, 50, 20, 25, 44, -10],
        borderColor: 'red',
        backgroundColor: 'red'
      },
      {
        label: 'Dataset 2',
        data: ['ON', 'ON', 'OFF', 'ON', 'OFF', 'OFF', 'ON'],
        borderColor: 'blue',
        backgroundColor: 'blue',
        stepped: true,
        yAxisID: 'y2',
      }
    ]
  },
  options: {
    scales: {
      y: {
        type: 'linear',
        position: 'left',
        stack: 'demo',
        stackWeight: 2,
        grid: {
          borderColor: 'red'
        }
      },
      y2: {
        type: 'category',
        labels: ['ON', 'OFF'],
        offset: true,
        position: 'left',
        stack: 'demo',
        stackWeight: 1,
        grid: {
          borderColor: 'blue'
        }
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://www.chartjs.org/dist/master/chart.js"></script>
</body>