Qt Graphs Migration from Qt Charts

The API and functionality between Qt Charts and Qt Graphs is slightly different. This article explains the differences between the API of both Qt Charts to Qt Graphs:

QML Import Statement

The import statement in Qt Charts:

import QtCharts

has to be changed to:

import QtGraphs

for Qt Graphs.

CMake Module Inclusion

The inclusion in Qt Charts:

find_package(Qt6 REQUIRED COMPONENTS Charts)
target_link_libraries(mytarget PRIVATE Qt6::Charts)

has to be changed to:

find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)

for Qt Graphs.

Qmake Module Inclusion

The inclusion in Qt Charts:

QT += charts

has to be changed to:

QT += graphs

for Qt Graphs.

Features missing in Qt Graphs

These features are missing in Qt Graphs in 6.8 release:

  • Qt Graphs Widgets

  • Candlestick charts

  • Box-and-whiskers chart

  • Titles and legends

  • Log value axis

  • Polar chart view

Theme APIs

The theming between 2D and 3D graphs is unified, for the theme settings, see GraphsTheme .

The generic color scheme of the whole graph is now controlled by a color scheme property, and series colors by a theme property. If color scheme is not explicitly set, it will follow the desktop theming (Light/Dark).

Enums

In Qt Graphs 2D, all the enums are implemented as scoped enums, for example, for the PieSlice.LabelOutside in Qt Charts, the corresponding enum in Qt Graphs 2D is PieSlice.LabelPosition.Outside.

Migrating chart series in QML

This section gives the examples of how to migrate you code with Qt Charts to the Qt Graphs 2D.

Migrating Area series

These code samples implement similar charts:

With Qt Charts:

With Qt Graphs:

Migrating Bar series

With Qt Charts:

With Qt Graphs:

Migrating Donut series

With Qt Charts:

With Qt Graphs:

Migrating Line series

With Qt Charts:

With Qt Graphs:

Migrating Pie series

With Qt Charts:

With Qt Graphs:

Migrating Scatter series

With Qt Charts:

With Qt Graphs:

Migrating Spline series

With Qt Charts:

With Qt Graphs: