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.