使用chart.js

时间:2016-12-14 03:56:15

标签: javascript charts chart.js axis-labels

我使用chart.js绘制三个不同的数据集。我使用了三个y轴(左边两个,右边一个)。我将轴标题添加到所有y轴。但是,左侧内侧标题非常接近外轴。我尝试在scaleLabel {}中使用margin和padding将轴与标题分开,但这似乎不起作用。有任何想法吗?

JSFiddle

picture showing axis title with no separation

请参阅以下示例代码:

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 个答案:

答案 0 :(得分:1)

这是chart.js中的未解决问题,请查看this