QChart determine the y coordinates by the x coordinate
Unsolved
General and Desktop
-
How to determine the y coordinates by the x coordinate. The x coordinate is known but the y is unknown
I use QChart , QLineSeries
Maybe there are functions for determining one number (y) by another (x)?
Or is it possible to find the intersection of the two QLineSeries? (blue and black)
-
It's not a QChart problem but a math one.
QLineSeries
dose nothing but interpolating linearly 2 points.
Take the closest 2 numbers in the series to x (the one just higher and the one just lower) and calculate the linear interpolationdouble yForX(double targetX){ const QList<QPointF> linePoints = lineSeries.points(); if(linePoints.isEmpty()) return 0; auto i=linePoints.begin(); if(i->x()<=targetX) return i->y(); // x < minimum for(const auto iEnd=linePoints.end();i!=iEnd;++i){ auto j=i; if(++j==iEnd) return i->y(); // x > maximum if(j->x()<targetX) continue; if(j->x()==targetX) return j->y(); return (targetX-i->x())*(j->y()-i->y())/(j->x()-i->x()); } Q_UNREACHABLE(); }