score:1

Accepted answer

if i understand well, you don't want stacking all the data in the same group, but the 'stack' parameter is the same for each data set. in the docs the 'stack' parameter identify a group id for combining multiple data. i suggest you split the data in different groups.

// create a canvas into the loaded .php page
  var canvas = document.createelement('canvas');
  div = document.getelementbyid('container');
  canvas.id = "mychart";
  canvas.style.zindex = 8;
  div.appendchild(canvas);
  const labels = [
      '8',
      '9',
      '11',
      '14',
      '17',
      '21',
      '8',
      '9',
      '11',
      '14',
      '17',
      '21',
  ];

  const data = {
      labels: labels,
      datasets: [{
              label: 'my fourth dataset',
              backgroundcolor: 'rgb(255,0,0)',
              bordercolor: 'rgb(255,0,0)',
              data: [3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8],
              stack: 'combined',
              type: 'bar'
          },
          {
              label: 'my fifth dataset',
              backgroundcolor: 'rgb(255,255,0)',
              bordercolor: 'rgb(255,255,0)',
              data: [3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8],
              stack: 'combined',
              type: 'bar'
          },
          {
              label: 'my sixth dataset',
              backgroundcolor: 'rgb(255,159,64)',
              bordercolor: 'rgb(255,159,64)',
              data: [3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8],
              stack: 'combined',
              type: 'bar'
          },
          {
              label: 'my seventh dataset',
              backgroundcolor: 'rgb(224,224,224)',
              bordercolor: 'rgb(224,224,224)',
              data: [3, 2, 5, 2, 2, 5, 8, 3, 2, 5, 2, 2, 5, 8],
              stack: 'combined',
              type: 'bar'
          },
          {
              label: 'my first dataset',
              backgroundcolor: 'rgb(30,144,255)',
              bordercolor: 'rgb(30,144,255)',
              data: [1, 10, 5, 2, 20, 30, 145, 1, 10, 5, 2, 20, 30, 45],
              stack: 'combined_first',
          },
          {
              label: 'my secound dataset',
              backgroundcolor: 'rgb(165,42,42)',
              bordercolor: 'rgb(165,42,42)',
              data: [1, 10, 5, 2, 20, 30, 145, 1, 10, 5, 2, 20, 30, 45],
              stack: 'combined_second',
          },
          {
              label: 'my third dataset',
              backgroundcolor: 'rgb(80,80,80)',
              bordercolor: 'rgb(80,80,80)',
              data: [3, 2, 5, 2, 2, 5, 5, 3, 2, 5, 2, 2, 5, 8],
              stack: 'combined_third',
          }
      ]
  };

  const config = {
      type: 'line',
      data: data,
      options: {
          plugins: {
              title: {
                  display: true,
                  text: 'chart'
              }
          },
          scales: {
              y: {
                  stacked: true
              }
          }
      },
  };
  const mychart = new chart(
      document.getelementbyid('mychart'),
      config
  );
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div id="container" class="wdc-canvas-size">
</div>


Related Query

More Query from same tag