Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart determine the y coordinates by the x coordinate

QChart determine the y coordinates by the x coordinate

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 160 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandres92
    wrote on last edited by
    #1

    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)
    Снимок экрана 2022-05-25 171028.jpg

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      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 interpolation

      double 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();
      }

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved