QBarSeries 类

The QBarSeries class presents data in bar graphs. 更多...

头: #include <QBarSeries>
CMake: find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
qmake: QT += graphs
在 QML: BarSeries
继承: QAbstractSeries

公共类型

枚举类 BarsType { Groups, Stacked, StackedPercent }
枚举类 LabelsPosition { Center, InsideEnd, InsideBase, OutsideEnd }

特性

公共函数

QBarSeries (QObject * parent = nullptr)
bool append (QBarSet * set )
bool append (const QList<QBarSet *> & sets )
QBarSet * at (qsizetype index )
QQmlComponent * barDelegate () const
QList<QBarSet *> barSets () const
qreal barWidth () const
QBarSeries::BarsType barsType () const
QList<QColor> borderColors () const
void clear ()
qsizetype count () const
qsizetype find (QBarSet * set ) const
bool insert (qsizetype index , QBarSet * set )
qreal labelsAngle () const
QString labelsFormat () const
qreal labelsMargin () const
QBarSeries::LabelsPosition labelsPosition () const
int labelsPrecision () const
bool labelsVisible () const
bool remove (QBarSet * set )
bool remove (qsizetype index )
void removeMultiple (qsizetype index , qsizetype count )
bool replace (const QList<QBarSet *> & sets )
bool replace (QBarSet * oldValue , QBarSet * newValue )
void replace (qsizetype index , QBarSet * set )
QList<QColor> seriesColors () const
void setBarDelegate (QQmlComponent * newBarDelegate )
void setBarWidth (qreal width )
void setBarsType (QBarSeries::BarsType type )
void setBorderColors (const QList<QColor> & newBorderColors )
void setLabelsAngle (qreal angle )
void setLabelsFormat (const QString & format )
void setLabelsMargin (qreal margin )
void setLabelsPosition (QBarSeries::LabelsPosition position )
void setLabelsPrecision (int precision )
void setLabelsVisible (bool visible = true)
void setSeriesColors (const QList<QColor> & newSeriesColors )
bool take (QBarSet * set )

重实现公共函数

virtual QAbstractSeries::SeriesType type () const override

信号

void barDelegateChanged ()
void barSetsChanged ()
void barWidthChanged ()
void barsTypeChanged (QBarSeries::BarsType type )
void barsetsAdded (const QList<QBarSet *> & sets )
void barsetsRemoved (const QList<QBarSet *> & sets )
void borderColorsChanged ()
void countChanged ()
void labelsAngleChanged (qreal angle )
void labelsFormatChanged (const QString & format )
void labelsMarginChanged (qreal margin )
void labelsPositionChanged (QBarSeries::LabelsPosition position )
void labelsPrecisionChanged (int precision )
void labelsVisibleChanged (bool visible )
void seriesColorsChanged ()
void setValueAdded (qsizetype index , qsizetype count , QBarSet * barset )
void setValueChanged (qsizetype index , QBarSet * barset )
void setValueRemoved (qsizetype index , qsizetype count , QBarSet * barset )
void updatedBars ()

详细描述

This class draws data by default as a series of bars grouped by category, with one bar per category from each bar set added to the series. It also supports horizontal bars and grouping bars as stacked.

A bar series needs the GraphsView x-axis to be set to a BarCategoryAxis and the y-axis set to ValueAxis .

另请参阅 QBarSet and QAbstractSeries .

成员类型文档编制

enum class QBarSeries:: BarsType

This enum value describes the type of the bar series:

常量 描述
QBarSeries::BarsType::Groups 0 Bar sets are grouped by category.
QBarSeries::BarsType::Stacked 1 Bar sets are stacked after each other by category.
QBarSeries::BarsType::StackedPercent 2 Bar sets are stacked after each other by category. The segment size corresponds to the percentage of the segment value compared with the total value of all segments in the stack.

enum class QBarSeries:: LabelsPosition

此枚举值描述数据值标签的位置:

常量 描述
QBarSeries::LabelsPosition::Center 0 Label is located in the center of the bar.
QBarSeries::LabelsPosition::InsideEnd 1 Label is located inside the bar at the top.
QBarSeries::LabelsPosition::InsideBase 2 Label is located inside the bar at the bottom.
QBarSeries::LabelsPosition::OutsideEnd 3 Label is located outside the bar at the top.

特性文档编制

barDelegate : QQmlComponent *

This property holds a custom QML component used for visualizing each of the bars. Instance of this component is created for each of the bar. When this is not defined, a default rectangle visualization for bars is used.

The dynamic properties available for this component are:

类型 名称 描述
QColor barColor The fill color of the bar. This value comes either from the QGraphsTheme or from QBarSet::color QBarSet overrides the color.
QColor barBorderColor The border color of the bar. This value comes either from the QGraphsTheme or from QBarSet::borderColor QBarSet overrides the color.
qreal barBorderWidth The width of the bar border. This value comes either from the QGraphsTheme or from QBarSet::borderWidth QBarSet overrides the width.
qreal barValue The value of the bar. This value comes from the QBarSet::values .
QString barLabel The label of the bar. This value comes from the QBarSet::label .
bool barSelected This value is true when the bar is selected, meaning that the bar index is in QBarSet::selectedBars .

To use any of these, add property with the defined name into your custom component. For example "property color barColor" and "property real barValue" .

访问函数:

QQmlComponent * barDelegate () const
void setBarDelegate (QQmlComponent * newBarDelegate )

通知程序信号:

void barDelegateChanged ()

[read-only] barSets : QList < QBarSet *> const

This property holds a list of sets added to the series.

访问函数:

QList<QBarSet *> barSets () const

通知程序信号:

void barSetsChanged ()

barWidth : qreal

此特性保持系列条形的宽度。

宽度单位是 X 轴的单位。条形的最小宽度为 0,且负值被视为 0。将宽度设为 0 意味着屏幕中的条形宽度为 1 像素,不管 X 轴的刻度。宽于 0 的条形按 X 轴的刻度比例缩放。

By default, the barWidth is 0.5 (bars will take 50% of the available width). The valid values range from 0.0 (0%) to 1.0 (100%).

注意: 当用于 QBarSeries ,此值指定一组条形的宽度,而不是单个条形的宽度。

访问函数:

qreal barWidth () const
void setBarWidth (qreal width )

通知程序信号:

void barWidthChanged ()

另请参阅 QBarSeries .

barsType : BarsType

This property holds the type of the bar series.

访问函数:

QBarSeries::BarsType barsType () const
void setBarsType (QBarSeries::BarsType type )

通知程序信号:

void barsTypeChanged (QBarSeries::BarsType type )

borderColors : QList < QColor >

This property holds the list of border colors to be used for all the objects in the series.

If there are more series than colors, the color list wraps and starts again with the first color in the list. If this is not set (default), colors from the QGraphsTheme::borderColors 会被使用。

访问函数:

QList<QColor> borderColors () const
void setBorderColors (const QList<QColor> & newBorderColors )

通知程序信号:

void borderColorsChanged ()

[read-only] count : const qsizetype

This property holds the number of bar sets in a bar series.

访问函数:

qsizetype count () const [见下文注意事项]

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

通知程序信号:

void countChanged ()

labelsAngle : qreal

This property holds the angle of the value labels in degrees.

访问函数:

qreal labelsAngle () const
void setLabelsAngle (qreal angle )

通知程序信号:

void labelsAngleChanged (qreal angle )

labelsFormat : QString

This property holds the format used for showing labels in a bar series.

QBarSeries 支持以下格式标签:

@value The value of the bar

For example, the following usage of the format tags would produce labels that show the value followed by the unit (u):

series->setLabelsFormat("@value u");
					

By default, the labels show the value of the bar. For the percent bar series, % is added after the value. The labels are shown on the plot area, if the bars are close to each other, the labels may overlap.

访问函数:

QString labelsFormat () const
void setLabelsFormat (const QString & format )

通知程序信号:

void labelsFormatChanged (const QString & format )

另请参阅 labelsVisible , labelsPosition ,和 labelsPrecision .

labelsMargin : qreal

This property holds the margin of the value labels in pixels.

This margin from side is used when labelsPosition is set to something else than LabelsPosition.Center 。默认值为 0 .

访问函数:

qreal labelsMargin () const
void setLabelsMargin (qreal margin )

通知程序信号:

void labelsMarginChanged (qreal margin )

labelsPosition : LabelsPosition

此特性保持值标签的位置。

访问函数:

QBarSeries::LabelsPosition labelsPosition () const
void setLabelsPosition (QBarSeries::LabelsPosition position )

通知程序信号:

void labelsPositionChanged (QBarSeries::LabelsPosition position )

另请参阅 labelsVisible and labelsFormat .

labelsPrecision : int

This property holds the maximum amount of significant digits shown in value labels.

默认值为 6。

访问函数:

int labelsPrecision () const
void setLabelsPrecision (int precision )

通知程序信号:

void labelsPrecisionChanged (int precision )

labelsVisible : bool

This property holds the visibility of the labels in a bar series. The default label visibility is false .

访问函数:

bool labelsVisible () const
void setLabelsVisible (bool visible = true)

通知程序信号:

void labelsVisibleChanged (bool visible )

seriesColors : QList < QColor >

This property holds the list of base colors to be used for all the objects in the series.

If there are more series than colors, the color list wraps and starts again with the first color in the list. If this is not set (default), colors from the QGraphsTheme::seriesColors 会被使用。

访问函数:

QList<QColor> seriesColors () const
void setSeriesColors (const QList<QColor> & newSeriesColors )

通知程序信号:

void seriesColorsChanged ()

成员函数文档编制

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

构造的空条形系列是 QObject 和子级对于 parent .

[invokable] bool QBarSeries:: append ( QBarSet * set )

Adds a set of bars specified by set to the bar series and takes ownership of it. If the set is null or it already belongs to the series, it will not be appended. Returns true if appending succeeded.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] bool QBarSeries:: append (const QList < QBarSet *> & sets )

Adds a list of bar sets specified by sets to a bar series and takes ownership of the sets. Returns true if all sets were appended successfully. If any of the sets is null or was previously appended to the series, nothing is appended and this function returns false . If any of the sets appears in the list more than once, nothing is appended and this function returns false .

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] QBarSet *QBarSeries:: at ( qsizetype index )

Retrieves the BarSet specified at the location index . Returns null if no BarSet was found.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

QList < QBarSet *> QBarSeries:: barSets () const

Returns a list of bar sets in a bar series. Keeps the ownership of the bar sets.

注意: Getter function for property barSets.

qreal QBarSeries:: barWidth () const

返回系列条形的宽度。

注意: getter 函数对于特性 barWidth。

另请参阅 setBarWidth ().

[signal] void QBarSeries:: barsetsAdded (const QList < QBarSet *> & sets )

This signal is emitted when the bar sets specified by sets are added to the series.

另请参阅 append () 和 insert ().

[signal] void QBarSeries:: barsetsRemoved (const QList < QBarSet *> & sets )

This signal is emitted when the bar sets specified by sets are removed from the series.

另请参阅 remove ().

[invokable] void QBarSeries:: clear ()

Removes all bar sets from the series and permanently deletes them.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] qsizetype QBarSeries:: count () const

返回条形系列的条形集数。

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

注意: getter 函数对于特性 count。

[invokable] qsizetype QBarSeries:: find ( QBarSet * set ) const

Returns the index of the first BarSet found as defined by set . Returns -1 if no BarSet was found.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] bool QBarSeries:: insert ( qsizetype index , QBarSet * set )

Inserts a bar set specified by set to a series at the position specified by index and takes ownership of the set. If the set is null or already belongs to the series, it will not be appended. Returns true if inserting succeeds.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

bool QBarSeries:: labelsVisible () const

返回标签的可见性。

注意: Getter function for property labelsVisible.

另请参阅 setLabelsVisible ().

[signal] void QBarSeries:: labelsVisibleChanged ( bool visible )

This signal is emitted when the labels' visibility changes to visible .

注意: 通知程序信号对于特性 labelsVisible .

另请参阅 labelsVisible () 和 setLabelsVisible ().

[invokable] bool QBarSeries:: remove ( QBarSet * set )

Removes the bar set specified by set from the series and permanently deletes it if the removal succeeds. Returns true 若集被移除。

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] bool QBarSeries:: remove ( qsizetype index )

移除 BarSet at the location index BarSet will be permanently deleted.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] void QBarSeries:: removeMultiple ( qsizetype index , qsizetype count )

Removes multiple BarSets from the series starting from index to a number of count . The BarSets will be permanently deleted.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] bool QBarSeries:: replace (const QList < QBarSet *> & sets )

Replaces the entire BarSet list inside of this BarSeries with the BarSets specified by sets . All of the original BarSets will be permanently deleted. Returns true if all BarSets are replaced.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] bool QBarSeries:: replace ( QBarSet * oldValue , QBarSet * newValue )

Replaces the BarSet 指定通过 oldValue with the one in newValue BarSet in oldValue will be permanently deleted if found inside the series. Returns true if the replace is successful.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] void QBarSeries:: replace ( qsizetype index , QBarSet * set )

Replaces the BarSet which is present at index with set . The original BarSet will be permanently deleted.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

void QBarSeries:: setBarWidth ( qreal width )

将系列条形的宽度设为 width .

注意: setter 函数对于特性 barWidth .

另请参阅 barWidth ().

void QBarSeries:: setLabelsVisible ( bool visible = true)

将条形系列中标签的可见性设为 visible .

注意: setter 函数对于特性 labelsVisible .

另请参阅 labelsVisible ().

[signal] void QBarSeries:: setValueAdded ( qsizetype index , qsizetype count , QBarSet * barset )

This signal is emitted when a barset's value is changed. index is the index of the barset in the series. The number of the added values is indicated countbarset is a pointer to the changed set.

[signal] void QBarSeries:: setValueChanged ( qsizetype index , QBarSet * barset )

This signal is emitted when a barset's value is changed. index is the index of the barset in the series. The barset is a pointer to the changed set.

[signal] void QBarSeries:: setValueRemoved ( qsizetype index , qsizetype count , QBarSet * barset )

This signal is emitted when a barset's value is changed. index is the index of the barset in the series. The number of the removed values is indicated countbarset is a pointer to the changed set.

[invokable] bool QBarSeries:: take ( QBarSet * set )

拿取单个 set 从系列。不删除条形集对象。

注意: The series remains the barset's parent object. You must set the parent object to take full ownership.

返回 true 若 take 操作成功。

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[override virtual] QAbstractSeries::SeriesType QBarSeries:: type () const

重实现访问函数为特性: QAbstractSeries::type .

返回条形系列。

[signal] void QBarSeries:: updatedBars ()

This signal is emitted when bars are updated.