Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Qwt x-axis should indicate hh:mm:ss
Forum Updated to NodeBB v4.3 + New Features

Qwt x-axis should indicate hh:mm:ss

Scheduled Pinned Locked Moved 3rd Party Software
17 Posts 5 Posters 18.2k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    Hi,

    I have started to use Qwt 6.0.1. At the moment I have a similar problem as described in "this thread":http://developer.qt.nokia.com/forums/viewthread/4890 . My value are measured in time. The x-axis should show hh:mm:ss. The QwtScaleDraw and a solution with reimplementation of QwtScaleDraw::label is certainly an option. Currently, I am still looking to find how define the values for different ticks.

    Can anyoneelse point me towards to look at in more detail?

    Thanks in advance.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Scylla
      wrote on last edited by
      #2

      Take a look at cpuplot example in the qwt source. This should be a good starting point.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        Thanks for pointing me to the example. This is certainly a good start.
        However, it shows also what I want to avoid. The labels drawn are:
        @
        02:38:46
        02:38:56
        02:39:06
        ...
        @
        It would be more logical to plot instead:
        @
        02:38:40
        02:38:50
        02:39:00
        ...
        @
        or for larger intervals:
        @
        02:30:00
        02:40:00
        02:50:00
        ...
        @
        This must be handled somewhere in qwt_scale_engine and qwt_interval, but without detailed background on the implementation it is a bit of a pain.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Scylla
          wrote on last edited by
          #4

          No, it depends on the x-achsis values. Put the the x-values in a 10s step and you will see the right scale.

          @QTime upTime = baseTime.addSecs((int)v);@

          convert your x-values from seconds to a QTime.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            hmmm ??
            I came to this statement here:
            @
            class TimeScaleDraw: public QwtScaleDraw
            {
            public:
            TimeScaleDraw(const QTime &base):
            baseTime(base)
            {
            }
            virtual QwtText label(double v) const
            {
            QTime upTime = baseTime.addSecs((int)v);
            return upTime.toString();
            }
            private:
            QTime baseTime;
            };
            @
            The step size of v is in tens.

            I have added also the stepsize in CpuPlot constructor to this statement:
            @
            setAxisScale(QwtPlot::xBottom, 0, HISTORY, 10);
            @

            But still the same.

            [edit] Update because some information was deleted prior to posting :-(

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Scylla
              wrote on last edited by
              #6

              Can you show how you use the "TimeScaleDraw", show more code.
              Anyway, may be you should take look at setAxisMajor(...) and setAxisMinor(...) methods of the QwtPlot.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                I am simply using the cpuplot example and apply some changes in order to find out how to do it.

                However, before we talking about different implementations. I have compiled the examples downloaded together with Qwt 6.0.1. In another thread I have read that there are significant differences to previous versions.

                This is the section I have changed with no success:
                @
                CpuPlot::CpuPlot(QWidget *parent):
                QwtPlot(parent),
                dataCount(0)
                {
                setAutoReplot(false);

                canvas()->setBorderRadius( 10 );
                
                plotLayout()->setAlignCanvasToScales(true);
                
                QwtLegend *legend = new QwtLegend;
                legend->setItemMode(QwtLegend::CheckableItem);
                insertLegend(legend, QwtPlot::RightLegend);
                
                setAxisTitle(QwtPlot::xBottom, " System Uptime [h:m:s]");
                setAxisScaleDraw(QwtPlot::xBottom, 
                    new TimeScaleDraw(cpuStat.upTime()/*.addSecs ( -6 )*/ ) );
                setAxisScale(QwtPlot::xBottom, 0, HISTORY, 10);
                setAxisMaxMajor ( QwtPlot::xBottom, 10 );
                setAxisMaxMinor ( QwtPlot::xBottom, 10 );
                setAxisLabelRotation(QwtPlot::xBottom, -50.0);
                setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
                
                /*
                 In situations, when there is a label at the most right position of the
                 scale, additional space is needed to display the overlapping part
                 of the label would be taken by reducing the width of scale and canvas.
                 To avoid this "jumping canvas" effect, we add a permanent margin.
                 We don't need to do the same for the left border, because there
                 is enough space for the overlapping label below the left scale.
                 */
                
                QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
                const int fmh = QFontMetrics(scaleWidget->font()).height();
                scaleWidget->setMinBorderDist(0, fmh / 2);
                
                setAxisTitle(QwtPlot::yLeft, "Cpu Usage [%]");
                setAxisScale(QwtPlot::yLeft, 0, 100, 10);
                

                @

                setAxisMaxMinor and setAxisMaxMajor has been added now.

                In
                @
                setAxisScaleDraw(QwtPlot::xBottom,
                new TimeScaleDraw(cpuStat.upTime()/.addSecs ( -6 )/ ) );
                @
                you see commented out addSecs. This certainly makes the labels look nicely rounded to every 10 seconds. Unfortunately it is changing basically the x-values now shifted by 6 seconds. So the graph is actually wrong.

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  I have found a solution for finding better fitting tick labels.

                  I have introduced following class:
                  @
                  class SecondsLinearScaleEngine : public QwtLinearScaleEngine
                  {
                  public:
                  virtual void autoScale( int maxSteps,
                  double &x1, double &x2, double &stepSize ) const;

                  protected:
                  double divideInterval( double interval, int numSteps ) const;
                  double ceil60 ( double v ) const;
                  };
                  @
                  You need to copy autoScale from its base class, since divideInterval is not virtual.
                  @
                  double SecondsLinearScaleEngine::divideInterval(
                  double intervalSize, int numSteps ) const
                  {
                  if ( numSteps <= 0 )
                  return 0.0;

                  double v = QwtScaleArithmetic::divideEps( intervalSize, numSteps );
                  if ( v < 1.0 ) 
                      return QwtScaleArithmetic::ceil125( v );
                  return ceil60( v );
                  

                  }
                  @
                  This is basically the same as of the base class. Only the return line has been substituted with the three last lines.
                  ceil60 does return multiples of 1,2,3,5 up to 30 seconds, minutes.

                  The equivalent of cpuplot requires two additional statements.
                  @
                  setAxisScaleDraw ( QwtPlot::xBottom, new TimeScaleDraw ( QTime() ) );
                  setAxisScaleEngine ( QwtPlot::xBottom, new SecondsLinearScaleEngine );
                  @

                  Thanks to Scylla for playing the sparing partner.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Scylla
                    wrote on last edited by
                    #9

                    Thank you for sharing your solution. I'm sure that I can use this in the next project where I have to use qwt havily. So may be I will/must have a deeper look in the qwt source. By the way, qwt is a very nice lib ;-)

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      Did you send your class to the QWT maintainer? He might be interested in adding this functionality to the library itself?

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        koahnig
                        wrote on last edited by
                        #11

                        Thanks for feedback.
                        at Scylla: Yes, it is a very nice lib. Even so, I grumbled a bit to myself about the documentation in the beginning, it was not so hard to extend. ;-)
                        at Andre: No. This is a good suggestion. However, at the time being it is a bit too much "hand-knitten". After some clean-up I will contact them.

                        Vote the answer(s) that helped you to solve your issue(s)

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          hassinoss
                          wrote on last edited by
                          #12

                          Hi Koahing,
                          I'm new in qwt and i work in a project similar to what you do, and i can't understund what does mean QwtScaleArithmetic::ceil125 in your example, it give me an error in my example . Can you help me ?
                          Ps : sorry for my english

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            koahnig
                            wrote on last edited by
                            #13

                            Welcome to devnet

                            I am not sure right away, but IIRC it is part of the old style in Qwt lib and had something to do with the rounding process.
                            You should change to Qwt 6.1.0 which has a date-time engine already as part of the library. Checkout "QwtDateScaleEngine":http://qwt.sourceforge.net/class_qwt_date_scale_engine.html
                            With Qt5.1 I had to change to this recent version 6.1.0 of Qwt and I abandoned my solution too.

                            Vote the answer(s) that helped you to solve your issue(s)

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              hassinoss
                              wrote on last edited by
                              #14

                              And what is your new solution?

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                koahnig
                                wrote on last edited by
                                #15

                                My code contains now following part
                                @
                                #if QWT_VERSION < 0x060100
                                setAxisScaleDraw ( QwtPlot::xBottom, new TimeScaleDraw ( QTime() ) );
                                setAxisScaleEngine ( QwtPlot::xBottom, new SecondsLinearScaleEngine );
                                #endif
                                #if QWT_VERSION >= 0x060100
                                setAxisScaleDraw ( QwtPlot::xBottom, new QwtDateScaleDraw ( Qt::UTC ) );
                                setAxisScaleEngine ( QwtPlot::xBottom, new QwtDateScaleEngine ( Qt::UTC ) );
                                #endif
                                @

                                The first part would be for my old-style as described above. However, it has a couple of deficiencies. For the use of Qt 5.1 I had to change to newer Qwt 6.1 lib. Qwt 6.1 did not work with my solution. I believe I ran into the same problem as you did. However, the second part of code above did solve it for me.

                                Vote the answer(s) that helped you to solve your issue(s)

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  veer4u
                                  wrote on last edited by
                                  #16

                                  Hello Sir
                                  I want to plot every 24 hours graph using qwt. Please suggest me How to take time scale on x-axis for 24 hours.

                                  Thanks inadvance

                                  1 Reply Last reply
                                  0
                                  • V Offline
                                    V Offline
                                    veer4u
                                    wrote on last edited by
                                    #17

                                    Hello Sir
                                    I want to plot every 24 hours graph using qwt. Please suggest me How to take time scale on x-axis for 24 hours.

                                    Thanks inadvance

                                    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