Results 1 to 3 of 3

Thread: Graphic view for scatter plot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Graphic view for scatter plot

    Hi,

    I am currently developing an application.. I need to generate a scatter graph... Can I use Graphics view for that.. If yes! Can you suggest something for that. If not then how can I do it in Qt.
    I would really appreciate your help.

    Cheers,

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Graphic view for scatter plot

    lots of ways... have a look at http://qwt.sourceforge.net/ (also, see separate Qwt-forum here)

  3. #3
    Join Date
    Jun 2009
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Graphic view for scatter plot

    Hi,
    Thanx for the reply..

    I actually did it with qwtcurve and Qframe combination but I need to add more functionality to that like zooming,scale and print. This is y I am looking now to qwtplot and Graphics view. Following is my code can you please tell me how can I add these features in this code...

    #include <qapplication.h>
    #include <qframe.h>
    //#include <qwt_scale_map.h>
    #include <qwt_plot_curve.h>
    #include <qwt_symbol.h>
    #include <qcolor.h>
    #include <qpainter.h>
    #include <math.h>
    #include <qwt_plot.h>

    //
    // Array Sizes
    //
    const int Size = 26;

    //
    // Arrays holding the values
    //
    double xval[Size];
    double yval[Size];
    QwtScaleMap xMap;
    QwtScaleMap yMap;

    QwtPlotCurve crv;

    class MainWin : public QFrame
    {

    public:
    MainWin();

    protected:
    virtual void paintEvent(QPaintEvent *);
    void drawContents(QPainter *p);
    };
    MainWin::MainWin()
    {
    int i;
    xMap.setScaleInterval(-0.5, 10.5);
    yMap.setScaleInterval(-1.1, 1.1);

    //
    // Frame style
    //
    setFrameStyle(QFrame::Box|QFrame::Raised);
    setLineWidth(2);
    setMidLineWidth(3);

    //
    // Calculate values
    //
    for(i=0; i<Size;i++)
    { xval[i] = double(i) * 10.0 / double(Size - 1);
    yval[i] = sin(xval[i]) * cos(2.0 * xval[i]);
    }

    //
    // define curve styles
    //
    QwtSymbol sym;

    sym.setStyle(QwtSymbol::Cross);
    sym.setPen(QColor(Qt::black));
    sym.setSize(5);


    sym.setStyle(QwtSymbol::XCross);
    sym.setPen(QColor(Qt::darkMagenta));
    crv.setSymbol(sym);
    crv.setStyle(QwtPlotCurve::NoCurve);



    //
    // attach data
    //

    crv.setRawData(xval,yval,Size);
    }

    //void MainWin::shiftDown(QRect &rect, int offset) const
    //{rect.translate(0, offset);
    //}


    void MainWin:aintEvent(QPaintEvent *event)
    {
    QFrame:aintEvent(event);

    QPainter painter(this);
    // painter.setClipRect(contentsRect());
    drawContents(&painter);
    }



    //
    // REDRAW CONTENTS
    //
    void MainWin::drawContents(QPainter *painter)
    {
    //int deltay,i;

    QRect r = contentsRect();



    //
    // draw curve
    //
    xMap.setPaintInterval(r.left(), r.right());
    yMap.setPaintInterval(r.top(), r.bottom());



    crv.draw(painter, xMap, yMap,r);

    //crv->attach(&plot);

    // shiftDown(r, deltay);


    }

    cheers,

Similar Threads

  1. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  2. File icon to graphic view
    By been_1990 in forum Qt Programming
    Replies: 10
    Last Post: 1st June 2009, 15:53
  3. World View Zooming factor
    By Pharell in forum General Programming
    Replies: 0
    Last Post: 6th November 2008, 13:04
  4. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  5. How to restrict graphic items in view
    By aamer4yu in forum Qt Programming
    Replies: 4
    Last Post: 13th November 2006, 07:46

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.