How to create two x-axes label using chart.js

前端 未结 3 1986
慢半拍i
慢半拍i 2020-12-16 00:54

There is a way to create two label for y-axes. But how do you make a multiple x-axes label in chart.js? eg: example as in this picture: How to group (two-level) axis labels<

3条回答
  •  醉话见心
    2020-12-16 01:56

    var myChart = new Chart(ctx, {
      type: "line",
      data: {
        datasets: [{
          data: [20, 50, 100, 75, 25, 0],
          label: "Left dataset",
    
          // This binds the dataset to the left y axis
          yAxisID: "left-y-axis",
        }, {
          data: [0.1, 0.5, 1.0, 2.0, 1.5, 0],
          label: "Right dataset",
    
          // This binds the dataset to the right y axis
          yAxisID: "right-y-axis",
        }],
        labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
      },
      options: {
        scales: {
          yAxes: [{
            id: "left-y-axis",
            type: "linear",
            position: "left",
          }, {
            id: "right-y-axis",
            type: "linear",
            position: "right",
          }],
        }, 
      },
    });
    

提交回复
热议问题