Skip to content

QCustomPlot

Xiangdong Yu edited this page Oct 2, 2015 · 3 revisions

#QCustomPlot

QCustomPlot is a Qt C++ widget for plotting and data visualization.

##Feature

  • No further dependencies and is well documented
  • Focuses on making good looking, publication quality 2D plots, graphs and charts
  • Offering high performance for realtime visualization applications

QCustomPlot can export to various formats such as vectorized PDF files and rasterized images like PNG, JPG and BMP. All outputs look consistent across the supported formats. QCustomPlot is the solution for displaying of realtime data inside the application as well as producing high quality plots for other media.

Have a look at the Setting Up and the Basic Plotting tutorials to get started.

##QCustomPlot Tutorials && Instructions ###Set Up ###Basic Plotting ###Example ###Caution


###Set Up

Download the QCP:

Getting QCustomPlot to work with your application is very easy:

  • Get the latest version of QCustomPlot from the download section.
  • Use the qcustomplot.h and qcustomplot.cpp file like any other ordinary class file.

###QtCreator User
Right click on the root entry of your project in the left sidebar and choose Add Existing Files...

In the appearing file dialog, select the qcustomplot.h and qcustomplot.cpp files, to add them to your project. If this is done, your project structure and .pro file should look something like this:

The project is now ready to use QCustomPlot. Place a regular QWidget on your form in the desired location. Right click on it and hit Promote to...

You won't see any immediate visual changes in QtCreator (or QtDesigner), but while running the application, you will see an empty plot with axes and grid lines.

  • Running the examples
    The QCustomPlot.tar.gz package in the download section contains the example projects ready to be compiled. Just extract the whole package to a new directory, navigate inside the example directories and run qmake; make. Alternatively you can open the .pro files in QtCreator and work with the examples from there.

###Basic Plotting

  1. First, you create a graph with QCustomPlot::addGraph.
  2. Then you assign the graph some data points (e.g. as a pair of QVectors for x and y values) and define the look of the graph (line style, scatter symbol, color, line pen, scatter size, filling...).
  3. Finally, call QCustomPlot::replot. Note that replot will be called automatically when the widget is resized and when the built-in user interactions are triggered (e.g. dragging axis ranges with mouse and zooming with mouse wheel). By default, QCustomPlot has four axes: xAxis, yAxis, xAxis2, yAxis2 of type QCPAxis, corresponding to the bottom, left, top and right axis. Their range (QCPAxis::setRange) defines which portion of the plot is currently visible.

Here's a minimal example, customPlot is a pointer to the QCustomPlot widget:

The output should look something like shown below:


###Example
The screenshots below show what can be achieved with QCustomPlot in only a few lines. To view the code, click on the respective image.


###Caution

  1. If you are using Qt version 5.0 upwards, you need to add printsupport to the QT variable in your .pro file. In the case shown above, this is done after a greaterThan(QT_MAJOR_VERSION, 4) conditional.

    2.QtGui include Error

     /home/shaarad/Qt5.0.0/5.0.0/gcc_64/include/QtGui/qopenglcontext.h:60:
        In file included from ../../../Qt5.0.0/5.0.0/gcc_64/include/QtGui/qopenglcontext.h:60:0,
     /home/shaarad/Qt5.0.0/5.0.0/gcc_64/include/QtGui/QtGui:33:
        from ../../../Qt5.0.0/5.0.0/gcc_64/include/QtGui/QtGui:33,
     /home/shaarad/Documents/JIGS/JIGS-FILE-SHARING-master/MainFrame.cpp:5:
        from ../JIGS-FILE-SHARING-master/MainFrame.cpp:5:
     /home/shaarad/Qt5.0.0/5.0.0/gcc_64/include/QtGui/qopengl.h:98: 
        error: GL/gl.h: No such file or directory  
    

Make Sure The Repo Sources Are Up to Date: sudo apt-get update
Install libraries: sudo apt-get install mesa-common-dev and sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
3. Install qmake-qt4 first if you want to compile through qmake.


##References