Add padding between two y-axis scales using chart.js

884 views Asked by At

I'm using chart.js to chart three different data sets. I'm using three y-axis (two on the left and one on the right). I added axis titles to all y-axis. However, the left inside title is really close to the outside axis. I've tried using margin and padding inside scaleLabel{} to separate the axis from the title, but that doesn't seem to work. Any ideas?

JSFiddle

picture showing axis title with no separation

See sample code below:

var leftInside = [
    ['2005-01-01','2005-02-01','2005-03-01','2005-04-01','2005-05-01','2005-06-01'],
    [32, 45, 56, 44, 67, 80]];

var leftOutside = [
['2005-01-01','2005-02-01','2005-03-01','2005-04-01','2005-05-01','2005-06-01'],
[2, -8, 12, 4, 15, 13]];

var right = [
['2005-01-01','2005-02-01','2005-03-01','2005-04-01','2005-05-01','2005-06-01'],
[133, 137, 145, 152, 160, 130]];

var ctx = document.getElementById("chartjs").getContext("2d");
var myChart = new Chart(ctx, {
  type: "line",
  data: {
    "labels": leftInside[0],
    "datasets": [{
      "label": "left outside",
      yAxisID: "y-axis-2",
      "data": leftInside[1]
    }, {
      "label": "price ($)",
      // "fill": "false",
      yAxisID: "y-axis-1",
      "data": right[1],
      backgroundColor: "rgba(000,111,111,.5)",
      // fill: false
    }, {
      "label": "left inside",
      yAxisID: "y-axis-0",
      "data": leftOutside[1]
      // fill: false
    }]
  },
  options: {
    scales: {
      yAxes: [{
        scaleLabel: {
          display: true,
          labelString: "left outside"
        },
        position: "left",
        "id": "y-axis-0",
      }, {
        scaleLabel: {
          display: true,
          labelString: "right",
        },
        position: "right",
        "id": "y-axis-1",
      }, {
        scaleLabel: {
          display: true,
          labelString: "left inside",
        },
        postion: "left",
        "id": "y-axis-2",
      }]
    }
  }
});
1

There are 1 answers

0
sandyJoshi On BEST ANSWER

This is open issue in chart.js check out this