Documentation

Qt-UI ChartKit Docs

Custom Qt chart controls for desktop data visualization, focused on line, column, pie, and scatter charts.

Overview

Qt-UI ChartKit Overview

ChartKit is a Qt Widget chart component library for desktop data visualization. The current chart controls use ChartKit's own OpenGL-rendered widget model. Application code should use the public ChartKit controls and data structures to configure data, themes, and interaction.

Base Classes

Type Description
UIGQChartBase Common chart rendering base class. It inherits QOpenGLWidget and manages themes, legend position, background color, animation, and tooltip overlay.
IUIGQWidgetBase Qt-UI common widget interface used for registration, JSON, layout, and styling integration.
UIGQChartTheme Theme data structure for background, plot area, title, axes, grid lines, hover guide, and palette.

Class Diagram

QWidget
  └─ QOpenGLWidget
      └─ UIGQtLib::UIGQChartBase
          ├─ UIGQtLib::UIGQLineChart      + IUIGQWidgetBase
          ├─ UIGQtLib::UIGQBarChart       + IUIGQWidgetBase
          ├─ UIGQtLib::UIGQOpenGLPieChart + IUIGQWidgetBase
          └─ UIGQtLib::UIGQScatterChart   + IUIGQWidgetBase

Chart Types

Chart Class typeName Data Entry
Line UIGQLineChart qtlinechart setCategories(...) + setSeries(...)
Bar UIGQBarChart qtbarchart setCategories(...) + setSeries(...)
Pie UIGQOpenGLPieChart qtopenglpiechart setSlices(...)
Scatter UIGQScatterChart qtscatterchart setSeries(...)

Basic Call Pattern

using namespace UIGQtLib;

auto* chart = new UIGQLineChart(parent);
chart->setTitle("Revenue Trend");
chart->setCategories({"Q1", "Q2", "Q3", "Q4"});
chart->setSeries("Revenue", {120.0, 160.0, 148.0, 210.0}, QColor(35, 128, 224));
chart->setThemePreset(kChartThemeMacarons);
chart->setLegendPosition(kChartLegendBottom);
chart->setTooltipVisible(true);
chart->setHoverEnabled(true);

API Entry Points

Use ChartKit APIs such as setSeries(...), setCategories(...), setSlices(...), and setThemePreset(...). Internal rendering objects are managed by the chart controls and are not application-level APIs.

Quick Start

Quick Start

This example creates a line chart through the public ChartKit API. A ChartKit chart is a QWidget, so it can be placed in a Qt layout, a page widget, or a Qt-UI container.

Include Headers

#include "UIGQLineChart.h"
#include "UIGQChartTheme.h"

For other chart types:

#include "UIGQBarChart.h"
#include "UIGQOpenGLPieChart.h"
#include "UIGQScatterChart.h"

Create the Chart

using namespace UIGQtLib;

auto* chart = new UIGQLineChart(parent);
chart->setMinimumSize(640, 360);
chart->setTitle("Monthly Orders");
Method Description Parameters Return
new UIGQLineChart(parent) Creates the line chart and lets Qt parent ownership manage its lifetime. parent: parent QWidget, or nullptr. UIGQLineChart*
setMinimumSize(int minw, int minh) Keeps the chart readable in layouts. minw: minimum width; minh: minimum height. void
setTitle(const QString& title) Sets the chart title. title: title text. void

Set Categories and Data

chart->setCategories({"Jan", "Feb", "Mar", "Apr", "May"});
chart->setSeries("Orders", {128, 152, 176, 163, 209}, QColor(35, 128, 224));
Method Description Parameters Return
setCategories(const QStringList& categories) Sets X-axis category labels. categories: category label list. void
setSeries(const QString& name, const QVector<double>& values, const QColor& color) Sets a single data series quickly. name: series name; values: value list; color: series color, optional. void

Theme and Interaction

chart->setThemePreset(kChartThemeMacarons);
chart->setLegendPosition(kChartLegendBottom);
chart->setTooltipMode(kChartTooltipItem);
chart->setTooltipVisible(true);
chart->setHoverEnabled(true);
chart->setAnimationEnabled(true);
Method Description Parameters Return
setThemePreset(UIGQChartThemePreset preset) Applies a built-in theme preset. preset: theme preset enum. void
setLegendPosition(UIGQChartLegendPosition position) Sets legend placement. position: legend position enum. void
setTooltipMode(UIGQChartTooltipMode mode) Controls tooltip behavior. mode: kChartTooltipNone, kChartTooltipItem, or kChartTooltipAxis. void
setTooltipVisible(bool visible) Shows or hides tooltips. visible: whether tooltips are visible. void
setHoverEnabled(bool enabled) Enables mouse hover interaction. enabled: whether hover is enabled. void
setAnimationEnabled(bool enabled) Enables chart drawing animation. enabled: whether animation is enabled. void

Refresh Data

chart->setSeries("Orders", latestValues, QColor(35, 128, 224));
chart->restartAnimation();

Do not update the chart through internal QtCharts objects. Re-apply data through ChartKit setters.

Usage Guide

Usage Guide

ChartKit uses a "control + data structure + theme" model. Business code prepares categories, values, points, or slices, then passes them to the chart control.

Shared Base API

All current ChartKit controls inherit UIGQChartBase.

Method Description Parameters Return
setThemePreset(UIGQChartThemePreset preset) Applies a built-in theme preset. preset: kChartThemeDefault, kChartThemeMacarons, kChartThemeShine, or kChartThemeDark. void
getThemePreset() Reads the current theme preset. None. UIGQChartThemePreset
setTheme(const UIGQChartTheme& theme) Applies a custom theme structure. theme: theme data including background, axes, grid lines, and palette. void
getTheme() Reads the current theme structure. None. const UIGQChartTheme&
setLegendPosition(UIGQChartLegendPosition position) Places the legend at top, right, bottom, or left. position: legend position enum. void
getLegendPosition() Reads the current legend position. None. UIGQChartLegendPosition
setBackgroundColor(const QColor& color) Sets the chart widget background. color: background color. void
getBackgroundColor() Reads the chart widget background. None. QColor
setAnimationEnabled(bool enabled) Enables or disables animation. enabled: whether animation is enabled. void
getAnimationEnabled() Reads the animation switch. None. bool
setAnimationDuration(int durationMs) Sets animation duration. durationMs: duration in milliseconds. void
getAnimationDuration() Reads animation duration. None. int
restartAnimation() Replays animation after data changes. None. void
getAnimationProgress() Reads current animation progress. None. qreal
setTooltipOverlay(const QPoint& anchorPos, const QString& text) Sets tooltip overlay content. anchorPos: tooltip anchor; text: tooltip text. void
clearTooltipOverlay() Clears tooltip overlay. None. void
hasTooltipOverlay() Checks whether tooltip overlay exists. None. bool
drawTooltipOverlay(QPainter& painter) Draws tooltip overlay, usually from chart internals. painter: painter used for drawing. void

Data Entry Points

Chart Main Data Structure Recommended Entry
Line UIGQLineChartSeries setCategories(...) + setSeries(...)
Bar UIGQBarChartSeries setCategories(...) + setSeries(...)
Pie UIGQOpenGLPieChartSlice setSlices(...)
Scatter UIGQScatterChartSeries setSeries(...)

Recommended Flow

auto* chart = new UIGQBarChart(parent);

chart->setTitle("Policy Status");
chart->setCategories({"Active", "Expiring", "Invalid"});

QVector<UIGQBarChartSeries> series;
UIGQBarChartSeries item;
item.name = "Policies";
item.values = {420, 15, 30};
item.fillColor = QColor(35, 128, 224);
series.append(item);

chart->setSeries(series);
chart->setThemePreset(kChartThemeShine);
chart->setTooltipVisible(true);
chart->setHoverEnabled(true);

Notes

  • Keep category count and value count aligned whenever possible.
  • Use QVector<UIGQLineChartSeries> or QVector<UIGQBarChartSeries> for multiple series.
  • Use clearSeries() or clearSlices() to remove current data.
  • Use setSeriesVisible(index, visible) to toggle series visibility without deleting data.
  • Application code should configure data structures, theme settings, and interaction options through ChartKit public methods. Internal rendering objects are managed by the chart controls.

Line Chart

Line Chart

Line charts show continuous trends, historical comparisons, monitoring curves, and time-like business metrics.

Base and Class Diagram

QOpenGLWidget
  └─ UIGQChartBase
      └─ UIGQLineChart + IUIGQWidgetBase

Data Structure

struct UIGQLineChartSeries
{
    QString name;
    QVector<double> values;
    QColor lineColor;
    QColor areaColor;
    bool showSymbol = true;
    bool smooth = false;
    bool showArea = false;
    bool visible = true;
    qreal lineWidth = 2.0;
    qreal areaOpacity = 0.22;
};

Methods

Method Description Parameters Return
setTitle(const QString& title) Sets the title. title: title text. void
getTitle() Reads the title. None. QString
setCategories(const QStringList& categories) Sets category labels. categories: X-axis category labels. void
getCategories() Reads category labels. None. QStringList
setValues(const QVector<double>& values) Sets default single-series values. values: value list. void
getValues() Reads default single-series values. None. QVector<double>
setSeries(const QString& name, const QVector<double>& values, const QColor& color) Quickly sets one line series. name: series name; values: value list; color: line color, optional. void
setSeries(const QVector<UIGQLineChartSeries>& series) Sets multiple line series. series: line series array. void
getSeries() Reads current line series. None. QVector<UIGQLineChartSeries>
clearSeries() Removes all series. None. void
setShowSymbol(bool show) Globally controls point symbols. show: whether symbols are visible. void
getShowSymbol() Reads symbol visibility. None. bool
setSmooth(bool smooth) Globally controls smooth curves. smooth: whether smoothing is enabled. void
getSmooth() Reads smoothing state. None. bool
setShowArea(bool show) Globally controls area fill. show: whether area fill is visible. void
getShowArea() Reads area fill state. None. bool
setSeriesVisible(int index, bool visible) Shows or hides a series. index: series index; visible: whether the series is visible. void
isSeriesVisible(int index) Checks whether a series is visible. index: series index. bool
setTooltipMode(UIGQChartTooltipMode mode) Sets tooltip mode. mode: tooltip mode enum. void
getTooltipMode() Reads tooltip mode. None. UIGQChartTooltipMode
setTooltipVisible(bool visible) Shows or hides tooltip. visible: whether tooltip is visible. void
getTooltipVisible() Reads tooltip visibility. None. bool
setHoverEnabled(bool enabled) Enables or disables hover interaction. enabled: whether hover is enabled. void
getHoverEnabled() Reads hover interaction state. None. bool
initDemoData() Loads demo data. None. void

Example

using namespace UIGQtLib;

auto* chart = new UIGQLineChart(parent);
chart->setTitle("CPU Usage");
chart->setCategories({"00:00", "00:05", "00:10", "00:15"});
chart->setSeries("CPU", {22.0, 35.0, 31.0, 48.0}, QColor(35, 128, 224));
chart->setSmooth(true);
chart->setShowSymbol(true);
chart->setThemePreset(kChartThemeMacarons);
chart->setTooltipMode(kChartTooltipAxis);
chart->setTooltipVisible(true);

setCategories(...) defines the horizontal labels. setSeries(...) provides the line name, values, and color. kChartTooltipAxis is useful when values should be inspected by category position.

Bar Chart

Bar Chart

Bar charts compare values across categories. The public class is UIGQBarChart; this chapter keeps the column-chart slug only for existing page compatibility.

Base and Class Diagram

QOpenGLWidget
  └─ UIGQChartBase
      └─ UIGQBarChart + IUIGQWidgetBase

Data Structure

struct UIGQBarChartSeries
{
    QString name;
    QVector<double> values;
    QColor fillColor;
    QColor borderColor;
    bool visible = true;
};

Methods

Method Description Parameters Return
setTitle(const QString& title) Sets the title. title: title text. void
getTitle() Reads the title. None. QString
setCategories(const QStringList& categories) Sets category labels. categories: category label list. void
getCategories() Reads category labels. None. QStringList
setValues(const QVector<double>& values) Sets default single-series values. values: value list. void
getValues() Reads default single-series values. None. QVector<double>
setSeries(const QString& name, const QVector<double>& values, const QColor& color) Quickly sets one bar series. name: series name; values: value list; color: fill color, optional. void
setSeries(const QVector<UIGQBarChartSeries>& series) Sets multiple bar series. series: bar series array. void
getSeries() Reads current bar series. None. QVector<UIGQBarChartSeries>
clearSeries() Removes all series. None. void
setSeriesVisible(int index, bool visible) Shows or hides a series. index: series index; visible: whether the series is visible. void
isSeriesVisible(int index) Checks whether a series is visible. index: series index. bool
setTooltipMode(UIGQChartTooltipMode mode) Sets tooltip mode. mode: tooltip mode enum. void
getTooltipMode() Reads tooltip mode. None. UIGQChartTooltipMode
setTooltipVisible(bool visible) Shows or hides tooltip. visible: whether tooltip is visible. void
getTooltipVisible() Reads tooltip visibility. None. bool
setHoverEnabled(bool enabled) Enables or disables hover interaction. enabled: whether hover is enabled. void
getHoverEnabled() Reads hover interaction state. None. bool
initDemoData() Loads demo data. None. void

Example

using namespace UIGQtLib;

auto* chart = new UIGQBarChart(parent);
chart->setTitle("Policy Overview");
chart->setCategories({"Active", "Expiring Soon", "Need Validation", "Expired"});
chart->setSeries("Policies", {420, 15, 30, 12}, QColor(35, 128, 224));
chart->setThemePreset(kChartThemeShine);
chart->setLegendPosition(kChartLegendBottom);
chart->setTooltipMode(kChartTooltipItem);
chart->setTooltipVisible(true);
chart->setHoverEnabled(true);

setCategories(...) defines category names. setSeries(name, values, color) is the fastest entry point for one grouped dataset. For multiple datasets, pass QVector<UIGQBarChartSeries> to setSeries(...).

Pie Chart

Pie Chart

Pie charts show part-to-whole relationships. The public class is UIGQOpenGLPieChart.

Base and Class Diagram

QOpenGLWidget
  └─ UIGQChartBase
      └─ UIGQOpenGLPieChart + IUIGQWidgetBase

Data Structure

struct UIGQOpenGLPieChartSlice
{
    QString name;
    double value = 0.0;
    QColor fillColor;
    bool visible = true;
};

Methods

Method Description Parameters Return
setTitle(const QString& title) Sets the title. title: title text. void
getTitle() Reads the title. None. QString
setSlices(const QVector<UIGQOpenGLPieChartSlice>& slices) Sets pie slices. slices: pie slice array. void
getSlices() Reads pie slices. None. QVector<UIGQOpenGLPieChartSlice>
clearSlices() Removes all slices. None. void
setInnerRadiusRatio(qreal ratio) Sets inner radius; 0 is a pie chart, larger values create a donut chart. ratio: inner radius ratio. void
getInnerRadiusRatio() Reads inner radius ratio. None. qreal
setAngleRange(qreal startAngleDegrees, qreal spanAngleDegrees) Sets start angle and span angle. startAngleDegrees: start angle; spanAngleDegrees: angle span. void
getStartAngle() Reads start angle. None. qreal
getSpanAngle() Reads angle span. None. qreal
setLeaderLineVisible(bool visible) Shows or hides leader lines. visible: whether leader lines are visible. void
getLeaderLineVisible() Reads leader line visibility. None. bool
setTooltipMode(UIGQChartTooltipMode mode) Sets tooltip mode. mode: tooltip mode enum. void
getTooltipMode() Reads tooltip mode. None. UIGQChartTooltipMode
setTooltipVisible(bool visible) Shows or hides tooltip. visible: whether tooltip is visible. void
getTooltipVisible() Reads tooltip visibility. None. bool
setHoverEnabled(bool enabled) Enables or disables hover interaction. enabled: whether hover is enabled. void
getHoverEnabled() Reads hover interaction state. None. bool
initDemoData() Loads demo data. None. void

Example

using namespace UIGQtLib;

auto* chart = new UIGQOpenGLPieChart(parent);
chart->setTitle("Traffic Sources");

QVector<UIGQOpenGLPieChartSlice> slices;

UIGQOpenGLPieChartSlice search;
search.name = "Search";
search.value = 1048;
search.fillColor = QColor(35, 128, 224);
slices.append(search);

UIGQOpenGLPieChartSlice direct;
direct.name = "Direct";
direct.value = 735;
direct.fillColor = QColor(62, 180, 98);
slices.append(direct);

chart->setSlices(slices);
chart->setInnerRadiusRatio(0.55);
chart->setTooltipMode(kChartTooltipItem);
chart->setTooltipVisible(true);

setSlices(...) is the data entry point. value is used to calculate proportions, so application code does not need to pre-compute percentages.

Scatter Chart

Scatter Chart

Scatter charts show relationships between two numeric dimensions, such as correlation, distribution, clusters, and outliers.

Base and Class Diagram

QOpenGLWidget
  └─ UIGQChartBase
      └─ UIGQScatterChart + IUIGQWidgetBase

Data Structure

struct UIGQScatterChartSeries
{
    QString name;
    QVector<QPointF> points;
    QColor color;
    bool visible = true;
    qreal symbolSize = 8.0;
};

Methods

Method Description Parameters Return
setTitle(const QString& title) Sets the title. title: title text. void
getTitle() Reads the title. None. QString
setSeries(const QVector<UIGQScatterChartSeries>& series) Sets scatter series. series: scatter series array. void
getSeries() Reads scatter series. None. QVector<UIGQScatterChartSeries>
clearSeries() Removes all series. None. void
setSeriesVisible(int index, bool visible) Shows or hides a series. index: series index; visible: whether the series is visible. void
isSeriesVisible(int index) Checks whether a series is visible. index: series index. bool
setTooltipMode(UIGQChartTooltipMode mode) Sets tooltip mode. mode: tooltip mode enum. void
getTooltipMode() Reads tooltip mode. None. UIGQChartTooltipMode
setTooltipVisible(bool visible) Shows or hides tooltip. visible: whether tooltip is visible. void
getTooltipVisible() Reads tooltip visibility. None. bool
setHoverEnabled(bool enabled) Enables or disables hover interaction. enabled: whether hover is enabled. void
getHoverEnabled() Reads hover interaction state. None. bool
initDemoData() Loads demo data. None. void

Example

using namespace UIGQtLib;

auto* chart = new UIGQScatterChart(parent);
chart->setTitle("Validation Samples");

QVector<UIGQScatterChartSeries> series;

UIGQScatterChartSeries passed;
passed.name = "Passed";
passed.points = {QPointF(12, 80), QPointF(18, 88), QPointF(25, 91)};
passed.color = QColor(62, 180, 98);
passed.symbolSize = 8.0;
series.append(passed);

UIGQScatterChartSeries warning;
warning.name = "Warning";
warning.points = {QPointF(10, 52), QPointF(20, 58), QPointF(28, 61)};
warning.color = QColor(232, 148, 54);
warning.symbolSize = 10.0;
series.append(warning);

chart->setSeries(series);
chart->setThemePreset(kChartThemeShine);
chart->setTooltipMode(kChartTooltipItem);
chart->setTooltipVisible(true);
chart->setHoverEnabled(true);

Each QPointF(x, y) is one scatter point. Each UIGQScatterChartSeries represents one group.

License

License

ChartKit provides community and commercial editions.

Commercial editions are intended for production Qt applications and include source packages, examples, resources, and update rights according to the purchased plan.