View Poll Results: Qwt: Scaling the x-Axis with strings how to do it ?

Voters
7. You may not vote on this poll
  • Qwt

    7 100.00%
  • Qt

    1 14.29%
Multiple Choice Poll.
Results 1 to 6 of 6

Thread: How to adapt the x-axis with strings instead of with numbers ?

  1. #1
    Join Date
    Aug 2010
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question How to adapt the x-axis with strings instead of with numbers ?

    Hello Friends,

    I am not new by Qt, however I am using the first time the Qwt library for my Purposes. Well, My Questions are following:
    a-) How can I get the x-axis of my Histogram scaled with strings instead with numbers ?
    b-) what does mean "intervals" and "values" in the following code. I understood it as "intervals" means the distance between each two beam (y-axis) and "value" means the value of this beam (x-axis) !

    QwtArray<QwtDoubleInterval> intervals(numValues);
    QwtArray<double> values(numValues);

    double pos = 0.0;
    for ( int t = 0; t < (int)intervals.size(); t++ )
    {
    const int width = 5 + rand() % 5; //15;
    const int value = rand() % 100;

    intervals[t] = QwtDoubleInterval(pos, pos + double(width));
    values[t] = 120; //value;

    pos += width;
    }

    c-) I just have to make a histogram for exactly 7 parameters (x-axis) looking like this:

    the x-axis MUST like this:

    |------------|------------|-------------|------------|------------|-----------|
    ABB BCC CDD DEE EFF GFF PPP

    Question: How can I can determine the width of each beam that I have use in order to calculate the "interval" ? I have tried all Qwt-Examples, but I do not understand the Calculation's philosophy behind that, so I can not move on. Please I need your help.
    Thanks.

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

    Default Re: How to adapt the x-axis with strings instead of with numbers ?

    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. ...
    4. virtual QwtText label( double value) const
    5. {
    6. if ( value == 0.0 )
    7. return "ABB";
    8. if ( value == 1.0 )
    9. return "BCC";
    10. ...
    11.  
    12. return QwtScaleDraw::label(value);
    13.  
    14. };
    15.  
    16. plot->setAxisScale(QwtPlot::xBottom, 0.0, 6.0, 1.0);
    17. plot->setAxisMaxMinor(QwtPlot::xBottom, 0);
    18. plot->setAxisScaleDraw(QwtPlot::xBottom, new YourScaleDraw());
    To copy to clipboard, switch view to plain text mode 

    Uwe

  3. #3
    Join Date
    Aug 2010
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to adapt the x-axis with strings instead of with numbers ?

    Hi Uwe,

    Many thanks for the Help, but I am still having problems to get it done. Here is a bit part of the source code:

    class ModulationScaleDraw: public QwtScaleDraw
    {
    public:
    ModulationScaleDraw()
    {
    }
    virtual QwtText label(double v) const
    {
    switch (int(v))
    { case 1: return QString("FM"); break;
    case 2: return QString("AM"); break;
    case 3: return QString("PM"); break;
    case 4: return QString("FA"); break;
    case 5: return QString("PA"); break;
    case 6: return QString("konst."); break;
    case 7: return QString("unbekannt");break;
    }
    }

    private:
    QStringList modlabel;
    };


    Main.cpp:


    {
    int pos = 0;
    const double width = 1.98;
    // Klassenbreite: = (x-max - x-min) / (2n)*1/3
    // (M_TYPE * ((dMaxX-dMinX) - dMinX))/ (dMaxX -dMinX);
    // (dMaxX-dMinX)/(M_TYPE);
    // (M_TYPE * ((dMaxX-dMinX) - dMinX))/ (dMaxX -dMinX);

    for (int iInterval = 0; iInterval < M_TYPE; iInterval++ )
    {
    intervals[iInterval] = QwtDoubleInterval(pos, pos + double(width));
    switch (iInterval)
    { case M_F : values [0] += fm_value; break;
    case M_P : values [1] += am_value; break;
    case M_A : values [2] += pm_value; break;
    case M_F_A : values [3] += fa_value; break;
    case M_P_A : values [4] += pa_value; break;
    case M_KEINE : values [5] += c_value; break;
    }

    pos += width;
    }

    histo->setData(QwtIntervalData(intervals,values));
    histo->attach(plotDiag);

    plot->setAxisTitle(QwtPlot::yLeft, " Anzahl ");
    plot->setAxisScale(QwtPlot::yLeft, 0.0, iP);

    //The system crashed here with following lines. TODO: Find the reasons ????

    plotDiag->setAxisScaleDraw(QwtPlot::xBottom, new ModulationScaleDraw());
    plotDiag->setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
    plotDiag->setAxisScale(QwtPlot::xBottom, 1.0, M_TYPE, 1.0);
    plotDiag->setAxisMaxMinor(QwtPlot::xBottom, 0);
    }

  4. #4
    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 adapt the x-axis with strings instead of with numbers ?

    does anyone know why this thread gets pushed? I don't see any new posting (except mine )

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,241
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to adapt the x-axis with strings instead of with numbers ?

    Probably someone has voted - for whatever this poll was good for,

    Uwe

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to adapt the x-axis with strings instead of with numbers ?

    I've closed the poll. It didn't make much sense anyway. If someone wants it reopened and has a good argument for doing so, let me know.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Unicode strings int Qt 4.2.1
    By mkrentovskiy in forum Qt Programming
    Replies: 12
    Last Post: 29th December 2011, 09:02
  2. Replies: 12
    Last Post: 18th May 2011, 20:40
  3. Replies: 0
    Last Post: 12th January 2010, 18:27
  4. Axis yLeft cuts of numbers
    By sun in forum Qwt
    Replies: 17
    Last Post: 9th October 2009, 21:36
  5. HowTo adapt window to my screensize?
    By bnilsson in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2008, 15:37

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.