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.