QCategoryAxis Class

QCategoryAxis 类将命名的范围置于坐标轴上。更多

Header: #include <QCategoryAxis>
In QML: CategoryAxis
Inherits: QValueAxis

公共类型

enum AxisLabelsPosition { AxisLabelsPositionCenter, AxisLabelsPositionOnValue }

属性

公共函数

QCategoryAxis(QObject *parent = nullptr)
virtual ~QCategoryAxis()
void append(const QString &categoryLabel, qreal categoryEndValue)
QStringList categoriesLabels()
int count() const
qreal endValue(const QString &categoryLabel) const
QCategoryAxis::AxisLabelsPosition labelsPosition() const
void remove(const QString &categoryLabel)
void replaceLabel(const QString &oldLabel, const QString &newLabel)
void setLabelsPosition(QCategoryAxis::AxisLabelsPosition position)
void setStartValue(qreal min)
qreal startValue(const QString &categoryLabel = QString()) const

重新实现的公共函数

virtual QAbstractAxis::AxisType type() const override

信号

void categoriesChanged()
void labelsPositionChanged(QCategoryAxis::AxisLabelsPosition position)

详细说明

该类可通过添加标注类别来解释底层数据。与QBarCategoryAxis 不同,QCategoryAxis 允许自由指定类别范围的宽度。

如何使用 QCategoryAxis 的示例代码:

QChartView *chartView = new QChartView;
QLineSeries *series = new QLineSeries;
// ...
chartView->chart()->addSeries(series);

QCategoryAxis *axisY = new QCategoryAxis;
axisY->setMin(0);
axisY->setMax(52);
axisY->setStartValue(15);
axisY->append("First", 20);
axisY->append("Second", 37);
axisY->append("Third", 52);
chartView->chart()->setAxisY(axisY, series);

成员类型文档

enum QCategoryAxis::AxisLabelsPosition

该枚举描述了类别标签的位置。

常数描述
QCategoryAxis::AxisLabelsPositionCenter0x0标签居中于类别。
QCategoryAxis::AxisLabelsPositionOnValue0x1标签定位到类别的上限。

属性文档

[read-only] categoriesLabels : const QStringList

该属性以字符串列表形式保存类别标签。

访问功能:

QStringList categoriesLabels()

[read-only] count : const int

该属性用于保存类别数量。

访问功能:

int count() const

labelsPosition : AxisLabelsPosition

该属性用于保存类别标签的位置。在值上定位时,坐标轴开头和结尾的标签可能会与其他坐标轴的标签重叠。

访问功能

QCategoryAxis::AxisLabelsPosition labelsPosition() const
void setLabelsPosition(QCategoryAxis::AxisLabelsPosition position)

通知信号:

void labelsPositionChanged(QCategoryAxis::AxisLabelsPosition position)

startValue : qreal

此属性保留坐标轴上第一个类别的低端。

访问函数:

qreal startValue(const QString &categoryLabel = QString()) const
void setStartValue(qreal min)

成员函数文档

[explicit] QCategoryAxis::QCategoryAxis(QObject *parent = nullptr)

构造一个轴对象,它是parent 的子对象。

[virtual noexcept] QCategoryAxis::~QCategoryAxis()

销毁对象。

void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue)

在轴上添加一个新类别,标签为categoryLabel 。类别标签必须是唯一的。categoryEndValue 指定类别的上限。它必须大于前一个类别的上限。否则,该方法将返回,但不会添加新的类别。

[signal] void QCategoryAxis::categoriesChanged()

当轴的类别发生变化时会发出该信号。

QStringList QCategoryAxis::categoriesLabels()

返回类别标签列表。

注: categoryLabels 属性的获取函数。

int QCategoryAxis::count() const

返回类别数。

注: 属性计数的获取函数。

qreal QCategoryAxis::endValue(const QString &categoryLabel) const

返回categoryLabel 所指定类别的上限。

void QCategoryAxis::remove(const QString &categoryLabel)

从坐标轴上删除标签categoryLabel 指定的类别。

void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabel)

newLabel 替换oldLabel 指定的现有类别标签。如果旧标签不存在,方法返回,不做任何更改。

void QCategoryAxis::setStartValue(qreal min)

min 设置为坐标轴上第一个类别的下限。如果轴上已经添加了类别,则传递的值必须小于已经定义的第一个类别范围的高端值。否则不会执行任何操作。

注: 属性startValue 的设置函数。

另请参阅 startValue() 。

qreal QCategoryAxis::startValue(const QString &categoryLabel = QString()) const

返回categoryLabel 所指定类别的下限。

注: 属性 startValue 的获取函数。

另请参阅 setStartValue().

[override virtual] QAbstractAxis::AxisType QCategoryAxis::type() const

重实现:QValueAxis::type() 常量。

返回轴的类型。

© 2025 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.