Results 1 to 10 of 10

Thread: How to know the value of a point on the graph?

  1. #1
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to know the value of a point on the graph?

    Hello. Can you please tell whether you can use, qwt To make the something like this:

    tr3.jpg
    Ie when you click on the chart, find the Y coordinate of the curve?

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to know the value of a point on the graph?

    no, you can't (without implementing that by yourself). a curve is basically a series of points. QwtPlotCurve can give you the nearest point to a specified coordinate.

    If you want exactly the y-value for any x-value, you have to find the x coordinates x_left and x_right of the nearest points where your x0 is in the middle. the curve is a straight line between these two points. now you need the y-values y_left and y_right of these two points. Then you can calculate the y0 using some triangulation.

    hth,
    Felix

  3. #3
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to know the value of a point on the graph?

    Thanks, connected Qwtpicker:
    Qt Code:
    1. d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    2. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    3. myPlot->canvas());
    4. d_picker->setRubberBandPen(QColor(Qt::green));
    5. d_picker->setRubberBand(QwtPicker::CrossRubberBand);
    6. d_picker->setTrackerPen(QColor(Qt::white));
    7.  
    8. int cp;
    9. cp = curv1->closestPoint(d_picker->trackerPosition());
    10. psetInterval->setNum(cp);
    11.  
    12.  
    13. connect(d_picker, SIGNAL(moved(QPoint)), SLOT(UpdVizir()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void TrendTop::UpdVizir()
    2. {
    3. int cp;
    4. cp = curv1->closestPoint(d_picker->trackerPosition());
    5. psetInterval->setNum(cp);
    6. }
    To copy to clipboard, switch view to plain text mode 
    I want to get the X coordinate in the label psetInterval. I tried all the signals picker, but psetInterval displayed an all-time, the number "1"
    How can I fix it?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know the value of a point on the graph?

    QwtPicker::trackerPosition is a point in widget - not in plot coordinates.

    Instead use a picker with a QwtPickerClickPointMachine and connect to "QwtPlotPicker::selected( const QPointF &pos )"
    Here you get the clicked point translated in plot coordinates - not some widget coordinate that is used for displaying the tracker text !

    Also note that QwtPlotCurve::closestPoint returns the index of a point - not a plot coordinate !

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    oddytz1989 (14th February 2012)

  6. #5
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to know the value of a point on the graph?

    I corrected:

    Qt Code:
    1. picker_m = new QwtPickerClickPointMachine();
    2. picker_m->setState(QwtPickerMachine::PointSelection);
    3. d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    4. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    5. myPlot->canvas());
    6. d_picker->setStateMachine(picker_m);
    7.  
    8. connect(d_picker, SIGNAL(selected(const QPointF &pos)), SLOT(UpdVizir()));
    To copy to clipboard, switch view to plain text mode 
    But anyway, nothing has changed.

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know the value of a point on the graph?

    Of course not - how should it work, when you throw away the coordinate of the selected signal and connect it to the same wrong UpdVizir slot.

    Uwe

  8. #7
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to know the value of a point on the graph?

    Could you tell what I need to fix?

    Qt Code:
    1. Object::connect: No such signal QwtPlotPicker::selected(const QPointF &pos)
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void TrendTop::UpdVizir()
    2. {
    3. int cp;
    4. cp = curv1->closestPoint(d_picker->trackerPosition());
    5. psetInterval->setNum(cp);
    6. }
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know the value of a point on the graph?

    Quote Originally Posted by oddytz1989 View Post
    Could you tell what I need to fix?
    Sorry I wrote nonsense of course QwtPlotCurve::closestPoint want a point in widget coordinates. You have to write something like this:

    Qt Code:
    1. connect( picker, SIGNAL( selected( const QPolygon & ), SLOT(UpdVizir( const QPolygon & )));
    To copy to clipboard, switch view to plain text mode 
    and

    Qt Code:
    1. void TrendTop::UpdVizir( const QPolygon &points )
    2. {
    3. if ( points.size() != 1 )
    4. return; // should never happen for point selections
    5.  
    6. double dist;
    7. int index = curv1->closestPoint( points[0], &dist );
    8. if ( index >= 0 && dist <= ... )
    9. {
    10. const QPointF found = curv1->sample( index );
    11. ....
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

  10. The following user says thank you to Uwe for this useful post:

    oddytz1989 (14th February 2012)

  11. #9
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to know the value of a point on the graph?

    Biiiiig thanks. The last question. How on the chart when you click the mouse show a vertical line?. I wrote:
    Qt Code:
    1. d_picker->setRubberBandPen(QColor(Qt::green));
    2. d_picker->setRubberBand(QwtPicker::VLineRubberBand);
    To copy to clipboard, switch view to plain text mode 
    But nothing works.

  12. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know the value of a point on the graph?

    Check the bode example. It uses a crosshair instead of a vertical line - but the rest should be the same.

    Uwe

  13. The following user says thank you to Uwe for this useful post:

    oddytz1989 (15th February 2012)

Similar Threads

  1. Replies: 3
    Last Post: 21st June 2011, 19:37
  2. Replies: 1
    Last Post: 3rd December 2009, 14:23
  3. display a plot point by point
    By oswalidos in forum Newbie
    Replies: 32
    Last Post: 13th March 2009, 15:37
  4. graph
    By sonu111 in forum Qwt
    Replies: 1
    Last Post: 15th December 2008, 22:14
  5. how to paint scene point by point
    By elessaar in forum Qt Programming
    Replies: 8
    Last Post: 4th September 2008, 20:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.