2017-08-10 185 views
0

我想在y軸上顯示帶有天數(2,4,6,8,10 ..)的條形圖,並在x軸上顯示org1,org2,org3的條形圖。默認情況下,天數在y軸上顯示爲10,20,30。你能不能讓我知道如何改變這一點。如何在primeng條形圖中更改y軸標籤?

** ** 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> 

** **輸出

enter image description here

回答

1

你需要指定圖表選項爲

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

,然後你可以改變y軸蜱在選項:

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

Thanks.It工作。 – Jan69