Chartjs柱状图位置

huangapple go评论85阅读模式
英文:

Chartjs bar chart position

问题

我正在尝试创建一个看起来像这个设计的条形图:

Chartjs柱状图位置

我的当前图表看起来像这样(忽略2个缺失的条形元素):

Chartjs柱状图位置

我有两个问题:

  1. 如何将这些条形移到紧贴y轴,就像设计中一样?

  2. 如何删除最后一个条形元素之后多余的x轴?

查看我在绘图上制作的这张图片,可以更好地理解我在说什么:

Chartjs柱状图位置

英文:

I'm trying to make a bar chart that looks like this design:

Chartjs柱状图位置

My current chart looks like this (ignore the 2 missing bar elements):

Chartjs柱状图位置

The two questions I have are:

  1. How can I shift the bars so that they're up against the y-axis like in the design?

  2. How can I remove the excess x-axis after the last bar element?

Look at this picture I did on paint to get a better idea of what I'm talking about:

Chartjs柱状图位置

答案1

得分: 1

尝试在options中将offset设置为false:

const options = {
  scales: {
    x: {
      offset: false,
    },
  },
};

offset等于true时,图表周围会有一些空间。如果为false,将删除该空间。

官方文档

英文:

Try to set the offset to false in the options:

const options = {
  scales: {
    x: {
      offset: false,
    },
  },
};

when offset is equal to true, there will be some space around the chart. If it is false, the space will be removed.

official document

huangapple
  • 本文由 发表于 2023年3月8日 18:35:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定