Stacked Linear / Category

Stacked Linear / Category - 图1

config setup

  1. const config = {
  2. type: 'line',
  3. data: data,
  4. options: {
  5. responsive: true,
  6. plugins: {
  7. title: {
  8. display: true,
  9. text: 'Stacked scales',
  10. },
  11. },
  12. scales: {
  13. y: {
  14. type: 'linear',
  15. position: 'left',
  16. stack: 'demo',
  17. stackWeight: 2,
  18. border: {
  19. color: Utils.CHART_COLORS.red
  20. }
  21. },
  22. y2: {
  23. type: 'category',
  24. labels: ['ON', 'OFF'],
  25. offset: true,
  26. position: 'left',
  27. stack: 'demo',
  28. stackWeight: 1,
  29. border: {
  30. color: Utils.CHART_COLORS.blue
  31. }
  32. }
  33. }
  34. },
  35. };
  1. const DATA_COUNT = 7;
  2. const NUMBER_CFG = {count: DATA_COUNT, min: 0, max: 100};
  3. const labels = Utils.months({count: 7});
  4. const data = {
  5. labels: labels,
  6. datasets: [
  7. {
  8. label: 'Dataset 1',
  9. data: [10, 30, 50, 20, 25, 44, -10],
  10. borderColor: Utils.CHART_COLORS.red,
  11. backgroundColor: Utils.CHART_COLORS.red,
  12. },
  13. {
  14. label: 'Dataset 2',
  15. data: ['ON', 'ON', 'OFF', 'ON', 'OFF', 'OFF', 'ON'],
  16. borderColor: Utils.CHART_COLORS.blue,
  17. backgroundColor: Utils.CHART_COLORS.blue,
  18. stepped: true,
  19. yAxisID: 'y2',
  20. }
  21. ]
  22. };

Docs