Results 1 to 4 of 4

Thread: Qwt and custom axis

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qwt and custom axis

    I would like to add to my project a statistics section, with charts, ecc. Searching in the forum I found links to wysota's charts, and Qwt. Since wysota's project implements only barchart I have downloaded qwt; it is very complete and powerful. I have made a simple application just to try it and learn the basics.

    My problem is this: my application should read data from a magazine database and get for each issue the number of a certain type of article (for example, reviews): so, Gen 07 - 5 reviews, Feb 07 - 3 reviews, Mar 07 - 5 reviews, etc, and build a line chart. Get the data is not the problem; it is have on x-axis the sequence of issues (Gen 07, Feb 07, Mar 07, ecc) instead of a numerical progression.

    Thanks
    Giuseppe CalÃ

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

    Default Re: Qwt and custom axis

    Please stop crossposting.

    Uwe

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qwt and custom axis

    Crossposting? Where?
    Giuseppe CalÃ

  4. #4
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qwt and custom axis

    I reply myself (some time happens); looking one of the example in the documentation I have found a simple solution; I have made this new class:

    Qt Code:
    1. class MonthsScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. MonthsScaleDraw()
    5. {
    6. }
    7. virtual QwtText label(double v) const
    8. {
    9. switch(int(v))
    10. {
    11. case 1:
    12. return QString("Jan '07");
    13. break;
    14. case 2:
    15. return QString("Feb '07");
    16. break;
    17. case 3:
    18. return QString("Mar '07");
    19. break;
    20. case 4:
    21. return QString("Apr '07");
    22. break;
    23. case 5:
    24. return QString("May '07");
    25. break;
    26. case 6:
    27. return QString("Jun '07");
    28. break;
    29. case 7:
    30. return QString("Jul '07");
    31. break;
    32. case 8:
    33. return QString("Aug '07");
    34. break;
    35. case 9:
    36. return QString("Sep '07");
    37. break;
    38. case 10:
    39. return QString("Oct '07");
    40. break;
    41. case 11:
    42. return QString("Nov '07");
    43. break;
    44. case 12:
    45. return QString("Dec '07");
    46. }
    47. }
    48. };
    To copy to clipboard, switch view to plain text mode 

    then in my derivate of QwtPlot

    Qt Code:
    1. ...
    2. setAxisTitle(QwtPlot::xBottom, "Issues");
    3. setAxisScaleDraw(QwtPlot::xBottom, new MonthsScaleDraw());
    4. setAxisScale(QwtPlot::xBottom, 1, 12);
    5. ...
    To copy to clipboard, switch view to plain text mode 

    Let me now if there is a better solution.

    Regards
    Giuseppe CalÃ

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.