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 .
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. |
此枚舉值描述數據值標簽的位置:
| 常量 | 值 | 描述 |
|---|---|---|
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. |
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 . |
| int | barIndex | Index of the bar, from 0 to the amount of bars - 1. [since 6.9] |
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 () |
此特性保持係列條形的寬度。
寬度單位是 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 .
This property holds the type of the bar series.
訪問函數:
| QBarSeries::BarsType | barsType () const |
| void | setBarsType (QBarSeries::BarsType type ) |
通知程序信號:
| void | barsTypeChanged (QBarSeries::BarsType type ) |
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 () |
This property holds the angle of the value labels in degrees.
訪問函數:
| qreal | labelsAngle () const |
| void | setLabelsAngle (qreal angle ) |
通知程序信號:
| void | labelsAngleChanged (qreal angle ) |
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 .
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 ) |
此特性保持值標簽的位置。
訪問函數:
| QBarSeries::LabelsPosition | labelsPosition () const |
| void | setLabelsPosition (QBarSeries::LabelsPosition position ) |
通知程序信號:
| void | labelsPositionChanged (QBarSeries::LabelsPosition position ) |
另請參閱 labelsVisible and labelsFormat .
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 ) |
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 ) |
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 .
Returns a list of bar sets in a bar series. Keeps the ownership of the bar sets.
注意: Getter function for property barSets.
返迴係列條形的寬度。
注意: 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.
[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 .
返迴標簽的可見性。
注意: 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 .
將係列條形的寬度設為 width .
注意: setter 函數對於特性 barWidth .
另請參閱 barWidth ().
將條形係列中標簽的可見性設為 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 count 。 barset 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 count 。 barset 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.