Collect and organize Qt applets-draw common curves and charts

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.