如何更改 primeng 条形图中的 y 轴标签?

How to change y axis label in primeng barchart?

我想显示一个条形图,在 y 轴上显示天数 (2,4,6,8,10..),在 x 轴上显示 org1,org2,org3。默认情况下,天数在 y 轴上显示为 10、20、30。你能告诉我如何改变它吗?

** component.ts **

 this.chartdata = {
            labels: ['Org1', 'Org2', 'Org3', 'Org4', 'Org5', 'Org6', 'Org7'],
            datasets: [
                {
                    label: '< 7 days',
                     backgroundColor: '#9CCC65',
                    borderColor: '#7CB342',
                    data: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
                },
                {
                    label: '< 14 days',
                    backgroundColor: '#f4eb3d',
                    borderColor: '#f4eb3d',
                    data: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
                },
                 {
                    label: '> 21 days',
                    backgroundColor: '#ef220b',
                    borderColor: '#ef220b',
                    data: [1, 3, 5, 7, 9,12, 14, 16, 18, 20, 22]
                }

            ]
        }

** HTML 页数 **

<p-chart type="bar" [data]="chartdata"></p-chart>

** 输出 **

您需要将图表选项指定为

<p-chart type="bar" [data]="chartdata" [options]="chartOptions"></p-chart>

然后您可以在选项中更改 y 轴刻度:

public chartOptions = {
  scales: {
    yAxes: [{
      ticks: {
        stepSize: 2,
        beginAtZero: true
      }
    }]
  }
}