QtCharts - How to set fixed Y axis scale?

161 views Asked by At

I am using Qt Framework (C++) to create a bar chart of percentages. How to make make the Y-axis that shows percentages always remain at 100% even if none of the values are near 100%?

In this picture, the maximum percentage of an instance is only 60 and hence the Y-axis shows only until 60. It does not show until 100.

In this picture, the maximum percentage is only 80 and so the Y-axis shows only until 80.

How to make the chart show a scale of 100 in the Y-axis all the time?

1

There are 1 answers

0
Bharath Ram On

Okay, I was setting the range as (100,100) instead of (0,100). The correct code is: axisY->setRange(0,100);

I also added axisY->applyNiceNumbers(); and agamAxisY->setTickCount(10); so that the graph is beautifully incremented by 10 percentage points from 0-100.

Hope this helps someone out there.