在本页

BarCategoryAxis QML Type

为图表的坐标轴添加类别。更多

Import Statement: import QtGraphs
In C++: QBarCategoryAxis
Inherits:

AbstractAxis

属性

信号

方法

  • void append(list categories)
  • void append(string category)
  • string at(int index)
  • void clear()
  • void insert(int index, string category)
  • void remove(int index)
  • void remove(string category)
  • void replace(string oldCategory, string newCategory)

详细说明

BarCategoryAxis 类型可设置为显示带有刻度线、网格线和阴影的轴线。在刻度线之间绘制类别。

以下 QML 代码段说明了如何使用 BarCategoryAxis:

GraphsView {
    anchors.fill: parent
    axisX: BarCategoryAxis {
        categories: ["2023", "2024", "2025"]
        lineVisible: false
    }
    axisY: ValueAxis { }
    BarSeries {
        BarSet {
            values: [7, 6, 9]
        }
    }
}

属性文档

categories : list

轴的类别。

count : int [read-only]

轴的类别数。

labelPosition : enumeration [since 6.11]

常数说明
BarCategoryAxis.Center标签居中对齐类别。
BarCategoryAxis.OnValue标签定位到类别的上限。

此属性在 Qt 6.11 中引入。

max : string

轴上的最大值。给定值应包含在categories 中。

min : string

轴上的最小值。给定值应包含在categories 中。

信号文档

categoriesChanged()

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

注: 相应的处理程序是onCategoriesChanged

categoryRangeChanged(string min, string max)

minmax 是新范围的最小值和最大值。

注: 相应的处理程序是onCategoryRangeChanged

countChanged()

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

注: 相应的处理程序是onCountChanged

maxChanged(string max)

当轴最大值变为max 时,将发出该信号。

注: 相应的处理程序是onMaxChanged

minChanged(string min)

当轴最小值变为min 时发出此信号。

注: 相应的处理程序是onMinChanged

方法文档

void append(list categories)

categories 添加到坐标轴。轴上的最大值将改为与categories 中的最后一个类别相匹配。如果之前没有定义类别,轴上的最小值也将改为与categories 中的第一个类别相匹配。

类别必须是有效的QString ,且不能重复。重复的类别将不会被添加。

void append(string category)

category 添加到坐标轴。坐标轴上的最大值将更改为与最后的category 匹配。如果之前未定义任何类别,轴上的最小值也将改为与category 匹配。

类别必须是有效的QString ,并且不能重复。重复的类别将不会被添加。

string at(int index)

返回index 中的类别。

void clear()

删除所有类别。将坐标轴范围的最大值和最小值设置为 QString::null。

void insert(int index, string category)

category 插入index 处的坐标轴。category 必须是有效的QString ,且不能重复。如果category 被预置或附加到其他类别,轴上的最小值和最大值也会相应更新。

void remove(int index)

从坐标轴index 上删除一个类别。删除当前设置坐标轴最大或最小值的类别会影响坐标轴范围。

void remove(string category)

从坐标轴中删除category 。删除当前设置坐标轴最大或最小值的类别会影响坐标轴范围。

void replace(string oldCategory, string newCategory)

newCategory 替换oldCategory 。如果轴上不存在oldCategory ,则不会执行任何操作。newCategory 必须是有效的QString ,且不能重复。如果最小或最大类别被替换,轴上的最小值和最大值也会相应更新。

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