how to set alignment of QChart axis
![alt text]( image url)
using QGraphicsView and scene and Qchart，but i can't set alignment of them , give some advice
QChartclass has the
setMarginsmethod which you could use to set a left margin on the plot with the smallest Y max label value, but the problem is then to determine which margin value would align the two axes exactly and in all cases.
The following seems to work:
QFont labelFont = m_chart1->axisY()->labelsFont(); QString str1("10000.0"); //set max. y label value here for chart1 QString str2("10.0"); //set max. y label value here for chart2 QFontMetrics fm(labelFont); int width1 = fm.boundingRect(str1).width(); int width2 = fm.boundingRect(str2).width(); QMargins margins = m_chart1->margins(); int marg1 = margins.left(); margins.setLeft(marg1 + width1 - width2); m_chart2->setMargins(margins);
So if you can get the maximum label strings on both Y axes, the above will align the two Y axes.
Although I have no experience with
QChart, I have been using the very convenient
QCustomPlotwidget to some limited extend:
It has a feature called
QCPMarginGroupwhich allows you to obtain the alignment you seek.
QCustomPlotwidget is simply added to your project by including only 2 files: a header and a .cpp file with no further dependencies and which you are free to modify to your needs.
This post is deleted!