Results 1 to 3 of 3

Thread: MultiBarChart Sample Legend

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default MultiBarChart Sample Legend

    I'd like to change the titles shown to the left of each sample to something different than 0, 1, 2... as shown in the image below.

    fghgh.jpg

    Thank you for any help.

  2. #2
    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: MultiBarChart Sample Legend

    You have to derive from QwtScaleDraw and overload the label method:

    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. virtual QwtText label( double value ) const
    5. {
    6. const int index = qRound( value );
    7. return ...
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 
    and

    Qt Code:
    1. plot->setAxisScaleDraw( QwtPlot::yLeft, new YourScaleDraw() );
    To copy to clipboard, switch view to plain text mode 
    Have a look at the distrowatch example, that returns a label from a string list ( name of a distro ).

    Of course this is not the most comfortable API for a bar chart - simply because it is using an API that is made for any type of coordinate system.
    One idea I have is to add an optional module on top of the current APIs, that offers plots with a less powerful and flexible API, but with a very easy one, that is tailored for specific plot types.

    Uwe

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

    Prof. (4th July 2013)

  4. #3
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: MultiBarChart Sample Legend

    Quote Originally Posted by Uwe View Post
    You have to derive from QwtScaleDraw and overload the label method:

    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. virtual QwtText label( double value ) const
    5. {
    6. const int index = qRound( value );
    7. return ...
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 
    and

    Qt Code:
    1. plot->setAxisScaleDraw( QwtPlot::yLeft, new YourScaleDraw() );
    To copy to clipboard, switch view to plain text mode 
    Have a look at the distrowatch example, that returns a label from a string list ( name of a distro ).

    Of course this is not the most comfortable API for a bar chart - simply because it is using an API that is made for any type of coordinate system.
    One idea I have is to add an optional module on top of the current APIs, that offers plots with a less powerful and flexible API, but with a very easy one, that is tailored for specific plot types.

    Uwe
    That worked perfectly, thanks Uwe.

    I'm still relatively new to Qt, considering what a massive system it is.
    Half of the time I google something I want to know about Qt, one of your posts is what eventually answers my question.

Similar Threads

  1. UTF-8 Issues in Sample
    By trevelyan in forum Newbie
    Replies: 6
    Last Post: 19th May 2011, 01:41
  2. Replies: 4
    Last Post: 18th November 2010, 13:00
  3. Sample for Mutithreading
    By HugoHiasl in forum Qt Programming
    Replies: 19
    Last Post: 1st July 2010, 07:43
  4. Problem with QSettings sample
    By neoclaw in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2010, 09:52
  5. mysql connection sample
    By mohanakrishnan in forum Newbie
    Replies: 3
    Last Post: 12th November 2009, 16:23

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.