The third-party libraries of charts commonly used by Qt are Qwt and kdChart. Qwt is doing better, which makes people feel very professional. Below is a small program collected on the Internet, for your reference and learning, and to lay the foundation for your own progress.
When using the QWT curve library, add the following path to the project file pro; otherwise, it cannot be compiled through:
DEFINES + = QWT_DLLCONFIG + = qwtLIBS + =-L "D:/Qt/4.8.5/lib"-lqwtd // change to your own QWT path INCLUDEPATH + = D: /Qt/4.8.5/include/QtQwt // change to your own QWT path
Procedure 1: Draw waveforms using the Qwt Library
# Include <QtGui/QApplication> # include <Qt/qmath. h> # include <QVector> # include <qwt_plot.h> # include <strong> # include <qwt_plot_panner.h> # include <qwt_legend.h> # include <qwt_point_data.h> int main (int argc, char * argv []) {QApplication a (argc, argv); QwtPlot (QwtText ("CppQwtExample1"); plot. resize (640,400); // set the axis name to plot. setAxisTitle (QwtPlot: xBottom, "x->"); plot. setAxisTitle (QwtPlot: yLeft, "y->"); // you can specify the range of the axis. setAxisScale (QwtPlot: xBottom, 0.0, 2.0 * M_PI); plot. setAxisScale (QwtPlot: yLeft,-1.0, 1.0); // you can specify plot on the right. insertLegend (new QwtLegend (), QwtPlot: RightLegend); // use the scroll wheel to zoom in/out (void) new qwtplotmagniier (plot. canvas (); // use the left mouse button to translate (void) new QwtPlotPanner (plot. canvas (); // calculate the curve data QVector <double> xs; QVector <double> ys; for (double x = 0; x <2.0 * M_PI; x + = (M_PI/10.0) {xs. append (x); ys. append (qSin (x);} // construct the curve data QwtPointArrayData * const data = new QwtPointArrayData (xs, ys); QwtPlotCurve curve ("Sine"); curve. setData (data); // set data curve. setStyle (QwtPlotCurve: Lines); // straight line form curve. setCurveAttribute (QwtPlotCurve: Fitted, true); // The curve is smoother. setPen (QPen (Qt: blue); // set the paint brush curve. attach (& plot); // append the curve to the plot. show (); return a.exe c ();}
This article from the "LinuxQt Jinan High-Tech Zone" blog, please be sure to retain this source http://qtlinux.blog.51cto.com/3052744/1318759