Below is a brief overview of different aspects of data visualization with QCustomPlot. If you are new to QCustomPlot and just want to start using it, it's recommended to look at the tutorials and examples at
This documentation is especially helpful as a reference, when you're familiar with the basic concept of how to use QCustomPlot and you wish to learn more about specific functionality. See the class overview for diagrams explaining the relationships between the most important classes of the QCustomPlot library.
Plottables are classes that display any kind of data inside the QCustomPlot. They all derive from QCPAbstractPlottable. For example, the QCPGraph class is a plottable that displays a graph inside the plot with different line styles, scatter styles, filling etc.
Since plotting graphs is such a dominant use case, QCustomPlot has a special interface for working with QCPGraph plottables, that makes it very easy to handle them:
A new graph can be created with QCustomPlot::addGraph and accessed with QCustomPlot::graph.
For all other plottables, the normal plottable interface is used: First, an instance of the respective plottable is created and added to the QCustomPlot, e.g.
The properties of the newly created plottable can then be accessed via the newCurve
pointer.
Plottables (including graphs) can be retrieved via QCustomPlot::plottable. Since the return type of that function is the abstract base class of all plottables, QCPAbstractPlottable, you will probably want to qobject_cast
the returned pointer to the respective plottable subclass. As usual, the cast returns zero if the plottable wasn't of that specific subclass.
All further interfacing with plottables (e.g how to set data) is specific to the plottable type. See the documentations of the subclasses: QCPGraph, QCPCurve, QCPBars, QCPStatisticalBox, QCPColorMap, QCPFinancial.
QCustomPlot has four default axes: xAxis (bottom), yAxis (left), xAxis2 (top), yAxis2 (right).
Their range is handled by the simple QCPRange class. You can set the range with the QCPAxis::setRange function. To change the axis scale type from a linear scale to a logarithmic scale, set QCPAxis::setScaleType to QCPAxis::stLogarithmic. The logarithm base can be set with QCPAxis::setScaleLogBase.
Each axis can be given an axis label (e.g. "Voltage (mV)") with QCPAxis::setLabel.
By default, an axis automatically creates and labels ticks in a sensible manner. See the following functions for tick manipulation:
QCPAxis::setTicks, QCPAxis::setAutoTicks, QCPAxis::setAutoTickCount, QCPAxis::setAutoTickStep, QCPAxis::setTickLabels, QCPAxis::setTickLabelType, QCPAxis::setTickLabelRotation, QCPAxis::setTickStep, QCPAxis::setTickLength, ...
The distance of an axis backbone to the respective viewport/widget border is called its margin. Normally, the margins are calculated automatically to fit the axis and tick labels. To change this, set QCPAxisRect::setAutoMargins to exclude the respective margin sides, and set the margins manually with QCPAxisRect::setMargins. The main axis rect can be accessed with QCustomPlot::axisRect(). A detailed explanation of the different margins/paddings/offset options is given in the QCPAxisRect and QCPAxis documentation.
Every QCustomPlot has one QCPLegend (as QCustomPlot::legend) by default. A legend is a small layout element inside the plot which lists the plottables with an icon of the plottable line/symbol and a name (QCPAbstractPlottable::setName). Plottables can be added and removed from the main legend via QCPAbstractPlottable::addToLegend and QCPAbstractPlottable::removeFromLegend. By default, adding a plottable to QCustomPlot automatically adds it to the legend, too. This behaviour can be modified with the QCustomPlot::setAutoAddPlottableToLegend property.
The QCPLegend provides an interface to access, add and remove legend items directly, too. See QCPLegend::item, QCPLegend::itemWithPlottable, QCPLegend::addItem, QCPLegend::removeItem for example.
Multiple legends are supported via the layout system (since a QCPLegend simply is a normal layout element).
QCustomPlot supports dragging axis ranges with the mouse (QCPAxisRect::setRangeDrag), zooming axis ranges with the mouse wheel (QCPAxisRect::setRangeZoom) and a complete selection mechanism.
The availability of these interactions is controlled with QCustomPlot::setInteractions. For details about the interaction system, see the documentation there.
Further, QCustomPlot always emits corresponding signals, when objects are clicked or doubleClicked. See QCustomPlot::plottableClick, QCustomPlot::plottableDoubleClick and QCustomPlot::axisClick for example.
Apart from plottables there is another category of plot objects that are important: Items. The base class of all items is QCPAbstractItem. An item sets itself apart from plottables in that it's not necessarily bound to any axes. This means it may also be positioned in absolute pixel coordinates or placed at a relative position on an axis rect. Further, it usually doesn't represent data directly, but acts as decoration, emphasis, description etc.
Multiple items can be arranged in a parent-child-hierarchy allowing for dynamical behaviour. For example, you could place the head of an arrow at a fixed plot coordinate, so it always points to some important area in the plot. The tail of the arrow can be anchored to a text item which always resides in the top center of the axis rect, independent of where the user drags the axis ranges. This way the arrow stretches and turns so it always points from the label to the specified plot coordinate, without any further code necessary.
For a more detailed introduction, see the QCPAbstractItem documentation, and from there the documentations of the individual standard items, to find out how to use them.
QCustomPlot uses an internal layout system to provide dynamic sizing and positioning of objects like the axis rect(s), legends and the plot title. They are all based on QCPLayoutElement and are arranged by placing them inside a QCPLayout subclass, like QCPLayoutGrid.
See the page about the layout system for details.
See the page about plot performance improvement.
QCustomPlot understands some preprocessor defines that are useful for debugging and compilation:
QCUSTOMPLOT_COMPILE_LIBRARY
QCUSTOMPLOT_USE_LIBRARY
QCUSTOMPLOT_CHECK_DATA
See the page Special Qt Flags if your project uses QT_NO_CAST_FROM_ASCII
, QT_NO_CAST_TO_ASCII
or QT_NO_KEYWORDS
.