本页内容

QCustomSeries Class

QCustomSeries 类支持呈现自定义图表类型。更多内容...

头文件: #include <QCustomSeries>
CMake: find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
qmake: QT += graphs
自: Qt 6.11
在 QML 中: CustomSeries
继承自: QAbstractSeries

属性

公共函数

void append()
void append(const QVariantMap &data)
QQmlComponent *delegate() const
void insert(qsizetype index)
void insert(qsizetype index, const QVariantMap &data)
qreal mapX(qreal x)
qreal mapY(qreal y)
void remove(qsizetype index)
void setCustomSeriesPainter(QCustomSeriesCanvasRenderer *painter)
void setDelegate(QQmlComponent *newDelegate)

公共槽位

void clear()

信号

受保护函数

virtual void updateDelegate(QQuickItem *item, qsizetype index)

详细说明

使用 QCustomSeries 创建自定义图表。可以将其视为一种散点图,允许您访问每个元素的自定义数据。

QCustomSeries 定义了一个委托,用于渲染添加到图表中的每个项目。每个项目都包含存储在 `QVariantMap` 中的用户定义数据。项目在图表中的索引也会自动添加到数据映射中。该系列会将此映射传递给基于委托创建的每个元素。委托决定如何使用这些数据。

要将数据映射到由QGraphsView 轴定义的渲染坐标上,请使用mapX 和mapY 函数。

注意:目前 ,自定义序列中的各个元素之间不会共享信息。因此,您无法实现自定义线形序列。

属性文档

delegate : QQmlComponent*

该委托用于将与提供的自定义数据相对应的元素插入到 QML 中。数据在CustomSeries 中定义,并通过“data”属性传递给受委托的元素。

访问函数:

QQmlComponent *delegate() const
void setDelegate(QQmlComponent *newDelegate)

通知器信号:

void delegateChanged()

成员函数文档

[invokable] void QCustomSeries::append()

将一个空数据项追加到序列中。

注意: 可通过元对象系统和 QML 调用此 函数。请参阅Q_INVOKABLE 。

[invokable] void QCustomSeries::append(const QVariantMap &data)

将由data 定义的数据项追加到序列中。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[slot] void QCustomSeries::clear()

清除所有数据项。

[invokable] void QCustomSeries::insert(qsizetype index)

在序列的index 位置追加一个空数据项。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QCustomSeries::insert(qsizetype index, const QVariantMap &data)

将由data 定义的数据项追加到序列的index 位置。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] qreal QCustomSeries::mapX(qreal x)

返回将x 轴空间坐标转换为渲染空间的坐标。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] qreal QCustomSeries::mapY(qreal y)

返回将y 轴空间坐标转换为渲染空间坐标的值。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QCustomSeries::remove(qsizetype index)

删除位于位置index 的数据项。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

void QCustomSeries::setCustomSeriesPainter(QCustomSeriesCanvasRenderer *painter)

当使用高性能画布绘制器后端时,将painter 设置为用于绘制该系列的画布绘制器。

QCustomSeries 接管painter 的所有权。在下一次同步该系列时,CanvasPainter-backend 渲染器将采用该对象,此后该对象仅由渲染器在渲染线程上销毁——绝不会由QCustomSeries 直接销毁。如果painter 在首次同步之前被替换或清空,或者该系列在此之前被销毁,QCustomSeries 将自行删除它。

[virtual protected] void QCustomSeries::updateDelegate(QQuickItem *item, qsizetype index)

由图渲染器调用,用于提供对表示数据的item 以及与该数据项对应的index 的访问权限。

重写此方法以实现QQuickItem 实例的自定义属性值。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.