qt chart equal axis (axis should form square not rectangle)

774 views Asked by At

How can I set my axis to be equally long in my QChart plot? I want to have my axis to form a square instead of a rectangle so that my contents are not distorted.

I want to change the left example image to look like the right. The axis should have equal length.

example

2

There are 2 answers

1
Marcel Petrick On BEST ANSWER

Ok, there are two different approaches. Based on how you painted your images, I think the scales have already the same range, so you have to change the layout of the QChartView (the widget which holds the QChart). Do this by using the usual setters like: 'setMinimumSize(width, height)' and 'setMaximumSize(width, height)'.

If you want to achieve the same scale, then set on QAxis 'setRange(min, max)' with min any max being the computed minimum of (xMin, yMin) and 'max = std::max(xMax, yMax)'.

0
pcdangio On

Use QtChart::setPlotArea(QRectF rect) to control the aspect ratio of the plot.