- Qt 6.9
- Qt Graphs
- QML Types
- QtGraphs
- BarCategoryAxis
- Qt Graphs | Commercial or GPLv3

# BarCategoryAxis QML Type

Adds categories to a graph's axes. More...

Import Statement: | `import QtGraphs`
In C++: | QBarCategoryAxis
Inherits: | AbstractAxis

- List of all members, including inherited members
- BarCategoryAxis is part of Qt Graphs QML Types for 2D.

## Properties

- categories : list
- count : int
- max : string
- min : string

## Signals

- categoriesChanged()
- categoryRangeChanged(string min, string max)
- countChanged()
- maxChanged(string max)
- minChanged(string min)

## Methods

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

## Detailed Description

The BarCategoryAxis type can be set up to show an axis line with tick marks, grid lines, and shades. Categories are drawn between the ticks.

The following QML snippet illustrates how to use BarCategoryAxis:

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

## Property Documentation

categories : list

The categories of an axis.

count : int `[read-only]`

The number of categories of an axis.

max : string

The maximum value on the axis. The given value should be contained in `categories`.

min : string

The minimum value on the axis. The given value should be contained in `categories`.

## Signal Documentation

categoriesChanged()

This signal is emitted when the categories of the axis change.

Note: The corresponding handler is `onCategoriesChanged`.

categoryRangeChanged(string min, string max)

This signal is emitted when the range of categories of the axis changes. min and max are the min and max of the new range.

Note: The corresponding handler is `onCategoryRangeChanged`.

countChanged()

This signal is emitted when the number of categories of an axis changes.

Note: The corresponding handler is `onCountChanged`.

maxChanged(string max)

This signal is emitted when the axis maximum value changes to max.

Note: The corresponding handler is `onMaxChanged`.

minChanged(string min)

This signal is emitted when the axis minimum value changes to min.

Note: The corresponding handler is `onMinChanged`.

## Method Documentation

append(list categories)

Appends categories to an axis. The maximum value on the axis will be changed to match the last category in categories. If no categories were previously defined, the minimum value on the axis will also be changed to match the first category in categories.

A category has to be a valid QString and it cannot be duplicated. Duplicated categories will not be appended.

append(string category)

Appends category to an axis. The maximum value on the axis will be changed to match the last category. If no categories were previously defined, the minimum value on the axis will also be changed to match category.

A category has to be a valid QString and it cannot be duplicated. Duplicated categories will not be appended.

string at(int index)

Returns the category at index.

clear()

Removes all categories. Sets the maximum and minimum values of the axis range to QString::null.

insert(int index, string category)

Inserts category to the axis at index. category has to be a valid QString and it cannot be duplicated. If category is prepended or appended to other categories, the minimum and maximum values on the axis are updated accordingly.

remove(int index)

Removes a category at index from the axis. Removing a category that currently sets the maximum or minimum value on the axis will affect the axis range.

remove(string category)

Removes category from the axis. Removing a category that currently sets the maximum or minimum value on the axis will affect the axis range.

replace(string oldCategory, string newCategory)

Replaces oldCategory with newCategory. If oldCategory does not exist on the axis, nothing is done. newCategory has to be a valid QString and it cannot be duplicated. If the minimum or maximum category is replaced, the minimum and maximum values on the axis are updated accordingly.