Results 1 to 3 of 3

Thread: Plot different curves with different colors

  1. #1
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Plot different curves with different colors

    Hello,
    I'm using Qwt to plot more than one curve, but I would like to have different color for each curve. I don't know why, but even if I change the value of the color using an increment my curves get always the same color. I checked the color mapping and I saw the values for each color, then I tried to start with Qt::Black (value 2) and use a counter to increment to the next color. Example below:

    Qt Code:
    1. graph[iGraphCounter].setAxes(QwtPlot::xBottom,QwtPlot::yLeft+iGraphCounter);
    2. graph[iGraphCounter].setTitle(object->legend.c_str());
    3. graph[iGraphCounter].setRenderHint(QwtPlotItem::RenderAntialiased);
    4. graph[iGraphCounter].setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    5. graph[iGraphCounter].setPen(QColor(Qt::black+iColorCounter));
    6. graph[iGraphCounter].setStyle(QwtPlotCurve::Lines);
    To copy to clipboard, switch view to plain text mode 

    But when I run the software all my curves are black. The increment for the graph handler is ok, the increment for the new y-axis is ok and the increment for the color is ok. I checked with a break point and my variable is incrementing fine and changing the value, but somehow the color doesn't change.

    Can anyone help me? I have no idea about what it's wrong. It would be nice some help.

    Thanks in advance
    Best Regards

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plot different curves with different colors

    Qt Code:
    1. graph[iGraphCounter].setPen( QColor( Qt::GlobalColor( Qt::black+iColorCounter ) ) );
    To copy to clipboard, switch view to plain text mode 

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

    cesroc (29th February 2012)

  4. #3
    Join Date
    Feb 2012
    Location
    Stuttgart / Germany
    Posts
    35
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Plot different curves with different colors

    Hello Spitfire,
    I found a solution today using the RGB values, but thanks anyways, good to know, because your solution is shorter. Using RGB I had to create a color mapping.
    Thanks.

Similar Threads

  1. Replies: 1
    Last Post: 27th July 2011, 20:37
  2. qwt several curves at a plot
    By freude3 in forum Qwt
    Replies: 4
    Last Post: 4th January 2011, 08:45
  3. Replies: 1
    Last Post: 7th April 2010, 17:26
  4. Replies: 1
    Last Post: 7th December 2009, 15:59
  5. Scatter plot with many colors
    By DKL1972 in forum Qwt
    Replies: 4
    Last Post: 29th June 2008, 12:15

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.