QChart Class
The QChart class manages the graphical representation of the chart's series, legends, and axes. 更多...
头文件: | #include <QChart> |
基类: | QGraphicsWidget |
派生类: |
公有类型
enum | AnimationOption { NoAnimation, GridAxisAnimations, SeriesAnimations, AllAnimations } |
flags | AnimationOptions |
enum | ChartTheme { ChartThemeLight, ChartThemeBlueCerulean, ChartThemeDark, ChartThemeBrownSand, ..., ChartThemeQt } |
enum | ChartType { ChartTypeUndefined, ChartTypeCartesian, ChartTypePolar } |
属性
|
|
- 14 个属性继承自 QGraphicsWidget
- 12 个属性继承自 QGraphicsObject
公有函数
QChart(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags()) | |
~QChart() | |
void | addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
void | addSeries(QAbstractSeries *series) |
int | animationDuration() const |
QEasingCurve | animationEasingCurve() const |
AnimationOptions | animationOptions() const |
QList<QAbstractAxis *> | axes(Qt::Orientations orientation = Qt::Horizontal | Qt::Vertical, QAbstractSeries *series = Q_NULLPTR) const |
QAbstractAxis * | axisX(QAbstractSeries *series = Q_NULLPTR) const |
QAbstractAxis * | axisY(QAbstractSeries *series = Q_NULLPTR) const |
QBrush | backgroundBrush() const |
QPen | backgroundPen() const |
qreal | backgroundRoundness() const |
ChartType | chartType() const |
void | createDefaultAxes() |
bool | isBackgroundVisible() const |
bool | isDropShadowEnabled() const |
bool | isPlotAreaBackgroundVisible() const |
bool | isZoomed() |
QLegend * | legend() const |
QLocale | locale() const |
bool | localizeNumbers() const |
QPointF | mapToPosition(const QPointF &value, QAbstractSeries *series = Q_NULLPTR) |
QPointF | mapToValue(const QPointF &position, QAbstractSeries *series = Q_NULLPTR) |
QMargins | margins() const |
QRectF | plotArea() const |
QBrush | plotAreaBackgroundBrush() const |
QPen | plotAreaBackgroundPen() const |
void | removeAllSeries() |
void | removeAxis(QAbstractAxis *axis) |
void | removeSeries(QAbstractSeries *series) |
void | scroll(qreal dx, qreal dy) |
QList<QAbstractSeries *> | series() const |
void | setAnimationDuration(int msecs) |
void | setAnimationEasingCurve(const QEasingCurve &curve) |
void | setAnimationOptions(AnimationOptions options) |
void | setAxisX(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR) |
void | setAxisY(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR) |
void | setBackgroundBrush(const QBrush &brush) |
void | setBackgroundPen(const QPen &pen) |
void | setBackgroundRoundness(qreal diameter) |
void | setBackgroundVisible(bool visible = true) |
void | setDropShadowEnabled(bool enabled = true) |
void | setLocale(const QLocale &locale) |
void | setLocalizeNumbers(bool localize) |
void | setMargins(const QMargins &margins) |
void | setPlotAreaBackgroundBrush(const QBrush &brush) |
void | setPlotAreaBackgroundPen(const QPen &pen) |
void | setPlotAreaBackgroundVisible(bool visible = true) |
void | setTheme(QChart::ChartTheme theme) |
void | setTitle(const QString &title) |
void | setTitleBrush(const QBrush &brush) |
void | setTitleFont(const QFont &font) |
QChart::ChartTheme | theme() const |
QString | title() const |
QBrush | titleBrush() const |
QFont | titleFont() const |
void | zoom(qreal factor) |
void | zoomIn() |
void | zoomIn(const QRectF &rect) |
void | zoomOut() |
void | zoomReset() |
- 53 个公有函数继承自 QGraphicsWidget
- 35 个公有函数继承自 QGraphicsLayoutItem
- 2 个公有函数继承自 QGraphicsObject
- 176 个公有函数继承自 QGraphicsItem
信号
void | plotAreaChanged(const QRectF &plotArea) |
- 1 个信号继承自 QGraphicsWidget
- 9 个信号继承自 QGraphicsObject
其他继承的成员
- 1 个公有槽函数继承自 QGraphicsWidget
- 1 个公有变量继承自 QGraphicsWidget
- 2 个公有变量继承自 QGraphicsItem
- 1 个静态公有成员继承自 QGraphicsWidget
- 24 个受保护的函数继承自 QGraphicsWidget
- 3 个受保护的函数继承自 QGraphicsLayoutItem
- 1 个受保护的函数继承自 QGraphicsObject
- 24 个受保护的函数继承自 QGraphicsItem
- 1 个受保护的槽函数继承自 QGraphicsObject
- 1 protected type inherited from QGraphicsLayoutItem
- 1 protected type inherited from QGraphicsItem
详细描述
The QChart class manages the graphical representation of the chart's series, legends, and axes.
QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical representation of different types of series and other chart related objects like legend and axes. To simply show a chart in a layout, the convenience class QChartView can be used instead of QChart. In addition, line, spline, area, and scatter series can be presented as polar charts by using the QPolarChart class.
参见 QChartView and QPolarChart.
成员类型
enum QChart::AnimationOption
flags QChart::AnimationOptions
This enum describes the animations enabled in the chart.
Constant | Value | Description |
---|---|---|
QChart::NoAnimation | 0x0 | Animation is disabled in the chart. This is the default value. |
QChart::GridAxisAnimations | 0x1 | Grid axis animation is enabled in the chart. |
QChart::SeriesAnimations | 0x2 | Series animation is enabled in the chart. |
QChart::AllAnimations | 0x3 | All animation types are enabled in the chart. |
The AnimationOptions type is a typedef for QFlags<AnimationOption>. It stores an OR combination of AnimationOption values.
enum QChart::ChartTheme
This enum describes the theme used by the chart.
A theme is a built-in collection of UI style related settings applied to all the visual elements of a chart, such as colors, pens, brushes, and fonts of series, as well as axes, title, and legend. The Chart themes example illustrates how to use themes.
Note: Changing the theme will overwrite all customizations previously applied to the series.
Constant | Value | Description |
---|---|---|
QChart::ChartThemeLight | 0 | The light theme, which is the default theme. |
QChart::ChartThemeBlueCerulean | 1 | The cerulean blue theme. |
QChart::ChartThemeDark | 2 | The dark theme. |
QChart::ChartThemeBrownSand | 3 | The sand brown theme. |
QChart::ChartThemeBlueNcs | 4 | The natural color system (NCS) blue theme. |
QChart::ChartThemeHighContrast | 5 | The high contrast theme. |
QChart::ChartThemeBlueIcy | 6 | The icy blue theme. |
QChart::ChartThemeQt | 7 | The Qt theme. |
enum QChart::ChartType
This enum describes the chart type.
Constant | Value | Description |
---|---|---|
QChart::ChartTypeUndefined | 0 | The chart type is not defined. |
QChart::ChartTypeCartesian | 1 | A cartesian chart. |
QChart::ChartTypePolar | 2 | A polar chart. |
属性
animationDuration : int
This property holds the duration of the animation for the chart.
访问函数:
int | animationDuration() const |
void | setAnimationDuration(int msecs) |
animationEasingCurve : QEasingCurve
This property holds the easing curve of the animation for the chart.
访问函数:
QEasingCurve | animationEasingCurve() const |
void | setAnimationEasingCurve(const QEasingCurve &curve) |
animationOptions : QChart::AnimationOptions
This property holds the animation options for the chart.
Animations are enabled or disabled based on this setting.
访问函数:
AnimationOptions | animationOptions() const |
void | setAnimationOptions(AnimationOptions options) |
backgroundRoundness : qreal
This property holds the diameter of the rounding circle at the corners of the chart background.
访问函数:
qreal | backgroundRoundness() const |
void | setBackgroundRoundness(qreal diameter) |
backgroundVisible : bool
This property holds whether the chart background is visible.
访问函数:
bool | isBackgroundVisible() const |
void | setBackgroundVisible(bool visible = true) |
参见 setBackgroundBrush(), setBackgroundPen(), and plotAreaBackgroundVisible.
chartType : const QChart::ChartType
This property holds whether the chart is a cartesian chart or a polar chart.
This property is set internally and it is read only.
访问函数:
ChartType | chartType() const |
参见 QPolarChart.
dropShadowEnabled : bool
This property holds whether the background drop shadow effect is enabled.
If set to true
, the background drop shadow effect is enabled. If set to false
, it is disabled.
Note: The drop shadow effect depends on the theme, and therefore the setting may change if the theme is changed.
访问函数:
bool | isDropShadowEnabled() const |
void | setDropShadowEnabled(bool enabled = true) |
locale : QLocale
This property holds the locale used to format various chart labels.
Labels are localized only when localizeNumbers is true
, except for QDateTimeAxis labels, which always use the QLocale set with this property.
Defaults to the application default locale at the time when the chart is constructed.
访问函数:
QLocale | locale() const |
void | setLocale(const QLocale &locale) |
参见 localizeNumbers.
localizeNumbers : bool
This property holds whether numbers are localized.
When true
, all generated numbers appearing in various series and axis labels will be localized using the QLocale set with the locale property. When false
, the C locale is always used. Defaults to false
.
Note: This property does not affect QDateTimeAxis labels, which always use the QLocale set with the locale property.
访问函数:
bool | localizeNumbers() const |
void | setLocalizeNumbers(bool localize) |
参见 locale.
margins : QMargins
This property holds the minimum margins allowed between the edge of the chart rectangle and the plot area.
The margins are used for drawing the title, axes, and legend.
访问函数:
QMargins | margins() const |
void | setMargins(const QMargins &margins) |
plotArea : const QRectF
This property holds the rectangle within which the chart is drawn.
The plot area does not include the area defined by margins.
访问函数:
QRectF | plotArea() const |
Notifier signal:
void | plotAreaChanged(const QRectF &plotArea) |
plotAreaBackgroundVisible : bool
This property holds whether the chart plot area background is visible.
Note: By default, the plot area background is invisible and the plot area uses the general chart background.
访问函数:
bool | isPlotAreaBackgroundVisible() const |
void | setPlotAreaBackgroundVisible(bool visible = true) |
参见 setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), and backgroundVisible.
theme : QChart::ChartTheme
This property holds the theme used for the chart.
访问函数:
QChart::ChartTheme | theme() const |
void | setTheme(QChart::ChartTheme theme) |
title : QString
This property holds the title of the chart.
The title is shown as a headline on top of the chart. Chart titles support HTML formatting.
访问函数:
QString | title() const |
void | setTitle(const QString &title) |
成员函数
QChart::QChart(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags())
Constructs a chart object that is a child of parent. The properties specified by wFlags are passed to the QGraphicsWidget constructor.
QChart::~QChart()
Deletes the chart object and its children, such as the series and axis objects added to it.
void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
Adds the axis axis to the chart aligned as specified by alignment. The chart takes the ownership of the axis.
参见 removeAxis(), createDefaultAxes(), and QAbstractSeries::attachAxis().
void QChart::addSeries(QAbstractSeries *series)
Adds the series series to the chart and takes ownership of it.
Note: A newly added series is not attached to any axes by default, not even those that might have been created for the chart using createDefaultAxes() before the series was added to the chart. If no axes are attached to the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other series that have properly attached axes, so always make sure you either call createDefaultAxes() after a series has been added or explicitly attach axes for the series.
参见 removeSeries(), removeAllSeries(), createDefaultAxes(), and QAbstractSeries::attachAxis().
QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation = Qt::Horizontal | Qt::Vertical, QAbstractSeries *series = Q_NULLPTR) const
Returns the axes attached to the series series with the orientation specified by orientation. If no series is specified, all axes added to the chart with the specified orientation are returned.
参见 addAxis() and createDefaultAxes().
QAbstractAxis *QChart::axisX(QAbstractSeries *series = Q_NULLPTR) const
Returns a pointer to the horizontal axis attached to the specified series. If no series is specified, the first horizontal axis added to the chart is returned.
参见 setAxisX(), addAxis(), and QAbstractSeries::attachAxis().
QAbstractAxis *QChart::axisY(QAbstractSeries *series = Q_NULLPTR) const
Returns a pointer to the vertical axis attached to the specified series. If no series is specified, the first vertical axis added to the chart is returned.
参见 setAxisY(), addAxis(), and QAbstractSeries::attachAxis().
QBrush QChart::backgroundBrush() const
Gets the brush that is used for painting the background of the chart area.
参见 setBackgroundBrush().
QPen QChart::backgroundPen() const
Gets the pen that is used for painting the background of the chart area.
参见 setBackgroundPen().
void QChart::createDefaultAxes()
Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to the chart will be deleted.
Note: This function has to be called after all series have been added to the chart. The axes created by this function will NOT get automatically attached to any series added to the chart after this function has been called. A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing if there are other series with properly attached axes also present.
Series type | X-axis | Y-axis |
---|---|---|
QXYSeries | QValueAxis | QValueAxis |
QBarSeries | QBarCategoryAxis | QValueAxis |
QPieSeries | None | None |
If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. If there are several series of different types added to the chart, then each series gets its own axes pair.
The axes specific to the series can be later obtained from the chart by providing the series as the parameter for the axes() function call. QPieSeries does not create any axes.
参见 axisX(), axisY(), axes(), setAxisX(), setAxisY(), and QAbstractSeries::attachAxis().
bool QChart::isZoomed()
Returns true
if any series has a zoomed domain.
QLegend *QChart::legend() const
Returns the legend object of the chart. Ownership stays with the chart.
QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series = Q_NULLPTR)
Returns the position on the chart that corresponds to the value value in the series specified by series.
QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series = Q_NULLPTR)
Returns the value in the series specified by series at the position specified by position in a chart.
QBrush QChart::plotAreaBackgroundBrush() const
Returns the brush used to fill the background of the plot area of the chart.
参见 plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), and setPlotAreaBackgroundBrush().
QPen QChart::plotAreaBackgroundPen() const
Returns the pen used to draw the background of the plot area of the chart.
参见 plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), and setPlotAreaBackgroundPen().
void QChart::removeAllSeries()
Removes and deletes all series objects that have been added to the chart.
参见 addSeries() and removeSeries().
void QChart::removeAxis(QAbstractAxis *axis)
Removes the axis axis from the chart. The chart releases the ownership of the specified axis object.
参见 addAxis(), createDefaultAxes(), and QAbstractSeries::detachAxis().
void QChart::removeSeries(QAbstractSeries *series)
Removes the series series from the chart. The chart releases the ownership of the specified series object.
参见 addSeries() and removeAllSeries().
void QChart::scroll(qreal dx, qreal dy)
Scrolls the visible area of the chart by the distance specified by dx and dy.
For polar charts, dx indicates the angle along the angular axis instead of distance.
QList<QAbstractSeries *> QChart::series() const
Returns all series that are added to the chart.
参见 addSeries(), removeSeries(), and removeAllSeries().
void QChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR)
Adds the axis axis to the chart and attaches it to the series series as a bottom-aligned horizontal axis. The chart takes ownership of both the axis and the series. Any horizontal axes previously attached to the series are deleted.
参见 axisX(), axisY(), setAxisY(), createDefaultAxes(), and QAbstractSeries::attachAxis().
void QChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series = Q_NULLPTR)
Adds the axis axis to the chart and attaches it to the series series as a left-aligned vertical axis. The chart takes ownership of both the axis and the series. Any vertical axes previously attached to the series are deleted.
参见 axisX(), axisY(), setAxisX(), createDefaultAxes(), and QAbstractSeries::attachAxis().
void QChart::setBackgroundBrush(const QBrush &brush)
Sets the brush that is used for painting the background of the chart area to brush.
参见 backgroundBrush().
void QChart::setBackgroundPen(const QPen &pen)
Sets the pen that is used for painting the background of the chart area to pen.
参见 backgroundPen().
void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
Sets the brush used to fill the background of the plot area of the chart to brush.
参见 plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), and plotAreaBackgroundBrush().
void QChart::setPlotAreaBackgroundPen(const QPen &pen)
Sets the pen used to draw the background of the plot area of the chart to pen.
参见 plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), and plotAreaBackgroundPen().
void QChart::setTitleBrush(const QBrush &brush)
Sets the brush used for drawing the title text to brush.
参见 titleBrush().
void QChart::setTitleFont(const QFont &font)
Sets the font that is used for drawing the chart title to font.
参见 titleFont().
QBrush QChart::titleBrush() const
Returns the brush used for drawing the title text.
参见 setTitleBrush().
QFont QChart::titleFont() const
Gets the font that is used for drawing the chart title.
参见 setTitleFont().
void QChart::zoom(qreal factor)
Zooms into the view by the custom factor factor.
A factor over 1.0 zooms into the view and a factor between 0.0 and 1.0 zooms out of it.
void QChart::zoomIn()
Zooms into the view by a factor of two.
void QChart::zoomIn(const QRectF &rect)
Zooms into the view to a maximum level at which the rectangle rect is still fully visible.
Note: This is not supported for polar charts.
void QChart::zoomOut()
Zooms out of the view by a factor of two.
void QChart::zoomReset()
Resets the series domains to what they were before any zoom method was called.
Note: This will also reset scrolling and explicit axis range settings specified between the first zoom operation and calling this method. If no zoom operation has been performed, this method does nothing.