可以指定条形图的偏移值吗?

时间:2019-07-12 16:42:59

标签: chart.js

我知道可以为条形图设置offset = true,但是是否可以为偏移量设置一个值?

我想在每个条上显示4个值,其中第4个值是其他3个值的总和。我有一个示例: https://jsfiddle.net/obxs5mz7/2

我想做的是设置灰色总条形超出其他3个条形的顶部,而不占用第4个条形的宽度。如果我将barThickness设置为210,它不会完全重叠。

或者其他有关如何实现这一目标的建议,谢谢。

代码示例:

var options = {
  scales: {
    xAxes: [{
      stacked: false,
      id: "bar-x-axis1",
      categoryPercentage: 1.90,
      barPercentage: 1.0,
      barThickness: 70,
    }, {
      display: false,
      stacked: false,
      id: "bar-x-axis2",
      barThickness: 70,
      // these are needed because the bar controller defaults set only the first x axis properties
      type: 'category',
      categoryPercentage: 0.8,
      barPercentage: 0.9,
      gridLines: {
        offsetGridLines: true
      },
      offset: true
    }, {
      display: false,
      stacked: false,
      id: "bar-x-axis3",
      barThickness: 70,
      // these are needed because the bar controller defaults set only the first x axis properties
      type: 'category',
      categoryPercentage: 0.8,
      barPercentage: 0.9,
      gridLines: {
        offsetGridLines: true
      },
      offset: true
    }, {
      display: false,
      stacked: true,
      id: "bar-x-axis4",
      barThickness: 210,
      // these are needed because the bar controller defaults set only the first x axis properties
      type: 'category',
      categoryPercentage: 0.8,
      barPercentage: 0.9,
      gridLines: {
        offsetGridLines: true
      },
      offset: true
    }],
    yAxes: [{
      stacked: false,
      ticks: {
        beginAtZero: true
      },
    }]

  }
};

0 个答案:

没有答案