PDA

View Full Version : Graphic view for scatter plot



hamid ghous
11th August 2009, 14:34
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,

caduel
11th August 2009, 14:52
lots of ways... have a look at http://qwt.sourceforge.net/ (also, see separate Qwt-forum here)

hamid ghous
11th August 2009, 15:27
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::paintEvent(QPaintEvent *event)
{
QFrame::paintEvent(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,