Results 1 to 4 of 4

Thread: QwtPlot - showing two values on x-Axis

  1. #1
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtPlot - showing two values on x-Axis

    Hi! I am pretty new to Qwt programming and I'm stuck at the Moment.

    I have a QwtPlot which shows drained Liquid over time. (Time is shown on x Axis) Now I would like to not just show the Time Value (in Seconds), but also the Simulation Steps of my Program. These two Values are going hand in hand and I have them together in a QVector<QPointF>.
    Now my problem is, how to get additional Information to the x Axis.

    So I want it to look somehow like this:
    0s (Step 0) - 10s(Step 15) - 20s(Step 25)...
    and so on, I hope you get what I want.

    I know i can derive from QwtScaleDraw, and I did it like this:

    Qt Code:
    1. class MyScaleDraw : public QwtScaleDraw
    2. {
    3. public:
    4. MyScaleDraw() : QwtScaleDraw() { }
    5. virtual ~MyScaleDraw() { }
    6. virtual QwtText label(double val) const
    7. {
    8. return QwtText(QString::number(val) + "(s)");
    9. }
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

    So now I get the (s) shown next to the values. But I guess I will not get what I want with this class and I couldn't quite figure out when exactly it is called. Also, it seems to first add the first Value of the Axis, then the last, then the inbetween. Therefore providing the Step Values or smth like that wouldn't work in my Opinion.

    I guess I may have to reimplement QwtPlot, but I wanted to know if there is a better solution, maybe a super easy one. I can't imagine that this is such a big Issue. Also I am a little bit rusty with deriving classes, so if I have to derrive from QwtPlot and reimplement some functions, I also would appreciate some help.

    I appreciate any help! Thanks in advance!

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,172
    Thanked 836 Times in 785 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot - showing two values on x-Axis

    Quote Originally Posted by Earinor View Post
    These two Values are going hand in hand and I have them together ...
    Then all you need is make your scale draw object being aware of this mapping and build the corresponding string.
    What exactly is the problem you are struggling with ?

    Uwe

  3. #3
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlot - showing two values on x-Axis [solved]

    Yeah sorry, I thought about a way to do this yesterday after posting the question. I feel a bit stupid now.
    But the only way I can think of is giving the CTor the mapping(the Vector) and then searching it through every time the label function is called. Because the axis is not built from left to right. I'm not that happy with it, but it works. I just think about the many steps the program has to do just for this, it isn't that slow, you can't see it, but when I write Code all over the place like this... well just my concerns about this solution.
    And in this example it is a List not a Vector, because I have some errors with QVector, but that's a question for antoher day... for this implementation it should definetly be a Vector.. ^^" If someone else is having the same issue and finding this code, please make a Vector or another mapping

    Qt Code:
    1. class MyScaleDraw : public QwtScaleDraw
    2. {
    3. public:
    4. MyScaleDraw(QList<QPointF> Vec) : QwtScaleDraw() {this->mVec=Vec; }
    5. virtual ~MyScaleDraw() { }
    6. virtual QwtText label(double val) const
    7. {
    8. for(int i=0; i< this->mVec.size();i++)
    9. {
    10. if(this->mVec[i].x()==val)
    11. {
    12. return QwtText(QString::number(val) + "("+QString::number(this->mVec[i].y())+")");
    13. }
    14. }
    15. return QwtText(QString::number(val));
    16. }
    17.  
    18. private:
    19. QList<QPointF> mVec;
    20.  
    21. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. this->mWidget.Graph->setAxisScaleDraw(QwtPlot::xBottom, new MyScaleDraw(this->mVec));
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtPlot - showing two values on x-Axis [solved]

    Quote Originally Posted by Earinor View Post
    I just think about the many steps the program has to do just for this, it isn't that slow, you can't see it, but
    Writing a linear search is of course the worst way to do it. As your array is sorted you can use something like qBinaryFind/qUpperBound/qLowerBound that brings it down to logarithmic order. Even better is introducing a hash tab where you would have a constant order.

    Simply doing what we all learned in school.

    Uwe

Similar Threads

  1. Cannot get the axis's current min and max values
    By Alexander111122 in forum Qwt
    Replies: 2
    Last Post: 24th February 2016, 15:18
  2. Showing small axis legend in QwtPlot
    By ahisham in forum Qwt
    Replies: 2
    Last Post: 25th February 2014, 19:48
  3. Showing a label in a QwtPlot
    By Momergil in forum Qwt
    Replies: 2
    Last Post: 22nd November 2013, 02:12
  4. Y-Axis values draw artifact
    By alex-krutikov in forum Qwt
    Replies: 3
    Last Post: 23rd October 2009, 08:48
  5. changing values for one class and showing it ..!
    By salmanmanekia in forum General Programming
    Replies: 6
    Last Post: 14th August 2008, 13:13

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.