Qt Charts Getting Started
Installing the Qt Charts module
Use the Package Manager
in Maintenance Tool
or the Online installer
to install the Qt Charts module. The module can be found under Qt Enterprise Add-Ons
in the package manager.
After installation Qt Charts documentation and examples are available in Qt Creator. Examples can be found on the examples page of Qt Creator by selecting the Qt Charts component from the drop-down menu.
The source code is installed into the QtCharts folder under EnterpriseAddOns.
Building Qt Charts
To build the Qt Charts module from source code yourself, set up a command prompt with an environment for building Qt applications, navigate to the directory containing qtcharts.pro
, and configure the project with qmake:
qmake
qmake should be run from the folder where Qt has been installed. For example, if Qt is built with -prefix /opt/MyXCompiledQt, then qmake should be run from /opt/MyXCompiledQt/bin/qmake.
After running qmake, build the project with make:
OS | Make command |
---|---|
Linux | make |
Windows (MinGw) | mingw32-make |
Windows (MSVC) | nmake |
OSX | make |
The above generates the default makefiles for your configuration, which is typically the release build if you are using precompiled binary Qt distribution. To build both debug and release, or one specifically, use one of the following qmake lines instead.
For debug builds:
qmake CONFIG+=debug make
or
qmake CONFIG+=debug_and_release make debug
For release builds:
qmake CONFIG+=release make
or
qmake CONFIG+=debug_and_release make release
For both builds (Windows/OS X only):
qmake CONFIG+="debug_and_release build_all" make
After building, install the module to your Qt directory:
make install
If you want to uninstall the module:
make uninstall
To build a statically linked version of the Qt Charts module, give the following commands:
qmake CONFIG+=static make make install
Running examples
Qt Charts examples are found under the examples
subdirectory. To build and run a single example, in this case qmlpolarchart, navigate to the example directory and enter the following commands:
qmake make ./qmlpolarchart
Note: On some platforms, such as Windows, the executable can be generated under debug or release folders, depending on your build.
Creating a simple application
To create a simple application, start by creating a new Qt Gui Application project in Qt Creator and add this line to the .pro
file of the project:
QT += charts
In the main.cpp
file, include the module headers and declare namespace usage:
#include <QtCharts> using namespace QtCharts;
Note: Since Qt Creator 3.0 the project created with Qt Quick Application wizard based on Qt Quick 2 template uses QGuiApplication by default. As Qt Charts utilizes Qt Graphics View Framework for drawing, QApplication must be used. The project created with the wizard is usable with Qt Charts after the QGuiApplication is replaced with QApplication.
For further code examples, see one of the Qt Charts examples:
The example shows how to create a simple area chart. | |
This example shows the drawing of dynamic data (microphone input). | |
The example shows how to create a bar chart. | |
This example shows how to use QAbstractItemModel derived model as the data for the bar series. | |
The example shows how to create a box-and-whiskers chart. | |
This example shows how to draw an additional element (a callout) on top of the chart. | |
The example shows the look and feel of the different built-in themes. | |
This example shows how to customize the appearance of the different elements on a chart. | |
The example shows how to use QLineChart with QDateTimeAxis. | |
This example shows how to use create a donut breakdown chart using QPieSeries API. | |
This example shows how to create a simple donut chart, and do some customizations to a slice. | |
This example shows how to draw dynamic data. | |
The example shows how to create a horizontal bar chart. | |
The example shows how to create a simple horizontal percent bar chart. | |
The example shows how to create a simple stacked horizontal bar chart. | |
This example shows how to detach the legend from the chart and how to attach it back. | |
The example shows how to make use of legend markers. | |
The example shows how to combine different charts and set the axes. | |
The example shows how to create a simple line chart. | |
The example shows how to use QLogValueAxis. | |
This example shows how to use the QAbstractItemModel derived model as the data for the series. | |
The example shows how to create a simple chart with two vertical axes. One for each series. | |
This example shows how to create a nested donuts chart using the QPieSeries API. | |
The example shows how to enable OpenGL acceleration for QLineSeries and QScatterSeries. | |
The example shows how to create a simple percent bar chart. | |
The example shows how to create a simple pie chart and do some customizations to a pie slice. | |
This example shows how the look and feel of a pie chart can be customized. | |
The example shows how to implement a piechart with drilldown effect. | |
The example shows how to create a simple polar chart with multiple different series. | |
This is a demonstration of how to use axes in your QML application. | |
This basic demonstration shows how to use the different chart types by using qml. | |
This application shows you how to customize different visual properties of a ChartView and series. | |
This example shows you how to create your own custom legend. | |
This application demonstrates how to use XmlListModel as a datasource for a Chart. | |
The example shows how to implement application with strict performance requirements using the Qt Charts QML API. | |
This is a demonstration on how to use a polar chart in your QML application. | |
This is a basic demonstration showing how to use the different chart types by using qml. | |
The example shows how to create a simple scatter chart. | |
This example shows how to create a simple scatter chart and how to interact with the chart. | |
The example shows how to create a simple spline chart. | |
The example shows how to create a simple stacked bar chart. | |
The example shows how to implement drilldown using a stacked barchart. | |
The example shows how to create a bar chart with negative bars. | |
The example shows how to create your own custom zooming effect |