Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeNg bar chart how to show a label for the y-axis

I have a requirement to show a vertical string as the yAxis for my bar chart.

I also need to squeeze by bars together and set a specific width for the bars.

I have added a screen shot of my mockups.

enter image description here

Any thoughts or hints on this?

like image 567
reza Avatar asked Sep 15 '25 19:09

reza


2 Answers

Try this to set Y axis label

basicOptions: any = {
scales: {
  yAxes: [
    {
      scaleLabel: {
        display: true,
        labelString: '% Cases/Status',
        fontColor: '#757575',
        fontSize: 12
      }
    }
  ]
}

}

like image 134
MeVimalkumar Avatar answered Sep 18 '25 09:09

MeVimalkumar


Since primeNg just implements the Chart.JS library, you can use your normal chartjs options, so to add for instance percentage signs to each step of the Y axos, you can do :

chartOptions = {
    scales: {
      yAxes: [
        {
          ticks: {
            callback: (label, index, labels) => {
              return label + '%';
            }
          }
        }
      ]
    }
  }

Then pass that class variable as options to the primeng chart component like this : <p-chart type="bar" [options]="chartOptions" [data]="data"></p-chart>.

Thus anything else you wanna add, you can read chartjs documentation/ chartjs related questions since they will apply to primeng.

like image 28
abdullahkady Avatar answered Sep 18 '25 08:09

abdullahkady