3

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

user7431005
  • 3,899
  • 4
  • 22
  • 49
  • Can you clarify your question ?Are you trying to have the same scale on X and Y axis ? – sandwood Sep 18 '18 at 18:02
  • I think what author meant is that resizing a qt chart arbitrary scales the axis to fill the plot area, and she/he desires to keep the aspect ratio fix 1:1 irrespective of the scaling – selyunin Aug 22 '20 at 16:45

2 Answers2

2

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)'.

Marcel Petrick
  • 454
  • 3
  • 15
1

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

pcdangio
  • 294
  • 2
  • 13