The QChart class manages the graphical representation of the chart's series, legends, and axes
QChart类管理图表的系列,图例和轴的图形表示
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.
Header头文件:#include <QChart>
Inherits继承:QGraphicsWidget
enum | AnimationOption { NoAnimation, GridAxisAnimations, SeriesAnimations, AllAnimations } |
flags | |
enum | ChartTheme { ChartThemeLight, ChartThemeBlueCerulean, ChartThemeDark, ChartThemeBrownSand, ..., ChartThemeQt } |
enum | ChartType { ChartTypeUndefined, ChartTypeCartesian, ChartTypePolar } |
|
|
QChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = Qt::WindowFlags()) | |
virtual | ~QChart() |
void | addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
void | addSeries(QAbstractSeries *series) |
int | animationDuration() const |
QEasingCurve | animationEasingCurve() const |
QChart::AnimationOptions | animationOptions() const |
QList<QAbstractAxis *> | axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = nullptr) const |
QBrush | backgroundBrush() const |
QPen | backgroundPen() const |
qreal | backgroundRoundness() const |
QChart::ChartType | chartType() const |
void | |
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 = nullptr) |
QPointF | mapToValue(const QPointF &position, QAbstractSeries *series = nullptr) |
QMargins | margins() const |
QRectF | plotArea() const |
QBrush | plotAreaBackgroundBrush() const |
QPen | plotAreaBackgroundPen() const |
void | |
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(QChart::AnimationOptions options) |
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 | setPlotArea(const QRectF &rect) |
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 |
x
void | plotAreaChanged(const QRectF &plotArea) |
- 2 signals inherited from QGraphicsWidget
- 9 signals inherited from QGraphicsObject
- 2 signals inherited from QObject
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.
AnimationOptions类型是QFlags <AnimationOption>的typedef。 它存储AnimationOption值的OR组合。
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.
主题是UI样式相关设置的内置集合,这些设置应用于图表的所有视觉元素,例如颜色,笔,画笔和系列字体,以及轴,标题和图例。 图表主题示例说明了如何使用主题。
注意:更改主题将覆盖先前应用于该系列的所有自定义项。
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. |
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.极坐标图。 |
Property Documentation
animationDuration : int
This property holds the duration of the animation for the chart.
此属性保存图表动画的持续时间。
Access functions:
int | animationDuration() const |
void | setAnimationDuration(int msecs) |
animationEasingCurve : QEasingCurve
This property holds the easing curve of the animation for the chart.此属性保存图表动画的缓动曲线。
Access functions:
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.
此属性保存图表的动画选项。
根据此设置启用或禁用动画。
Access functions:
QChart::AnimationOptions | animationOptions() const |
void | setAnimationOptions(QChart::AnimationOptions options) |
backgroundRoundness : qreal
This property holds the diameter of the rounding circle at the corners of the chart background.
此属性保存在图表背景的角处的圆角的直径。
Access functions:
qreal | backgroundRoundness() const |
void | setBackgroundRoundness(qreal diameter) |
backgroundVisible : bool
This property holds whether the chart background is visible.此属性保存图表背景是否可见。
Access functions:
bool | isBackgroundVisible() const |
void | setBackgroundVisible(bool visible = true) |
See also 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.
此属性保存图表是笛卡尔图还是极坐标图。
此属性在内部设置,并且是只读的。
Access functions:
QChart::ChartType | chartType() const |
See also 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.
此属性保存是否启用背景阴影效果。
如果设置为true,则启用背景阴影效果。 如果设置为false,则将其禁用。
注意:阴影效果取决于主题,因此,如果更改主题,则设置可能会更改。
Access functions:
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.
此属性保存用于格式化各种图表标签的语言环境。
仅当localizeNumbers为true时才对标签进行本地化,但QDateTimeAxis标签除外,该标签始终使用通过此属性设置的QLocale。
构造图表时,默认为应用程序默认语言环境。
Access functions:
QLocale | locale() const |
void | setLocale(const QLocale &locale) |
See also 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.
此属性保存数字是否本地化。
设置为true时,将使用带有locale属性的QLocale集来定位出现在各个系列和轴标签中的所有生成的数字。 如果为false,则始终使用C语言环境。 默认为false。
注意:此属性不会影响QDateTimeAxis标签,该标签始终使用通过locale属性设置的QLocale。
Access functions:
bool | localizeNumbers() const |
void | setLocalizeNumbers(bool localize) |
See also 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.
此属性保存图表矩形的边缘和绘图区域之间允许的最小边距。
边距用于绘制标题,轴和图例。
Access functions:
QMargins | margins() const |
void | setMargins(const QMargins &margins) |
plotArea : QRectF
This property holds the rectangle within which the chart is drawn.
The plot area does not include the area defined by margins. By default this will resize if inside a QChartView. If an explicit size is set for the plot area then it will respect this, to revert back to the default behavior, then calling setPlotArea(QRectF()); will achieve this.
此属性保存在其中绘制图表的矩形。
绘图区域不包括由边距定义的区域。 默认情况下,如果在QChartView中,它将调整大小。 如果为绘图区域设置了显式大小,则它将遵循此要求,以恢复为默认行为,然后调用setPlotArea(QRectF());。 将实现这一目标。
Access functions:
QRectF | plotArea() const |
void | setPlotArea(const QRectF &rect) |
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.
此属性保存图表绘图区域背景是否可见。
注意:默认情况下,绘图区背景是不可见的,并且绘图区使用常规图表背景。
Access functions:
bool | isPlotAreaBackgroundVisible() const |
void | setPlotAreaBackgroundVisible(bool visible = true) |
See also setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), and backgroundVisible.
theme : QChart::ChartTheme
This property holds the theme used for the chart.此属性保存用于图表的主题。
Access functions:
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.
此属性保存图表的标题。
标题显示为图表顶部的标题。 图表标题支持HTML格式。
Access functions:
QString | title() const |
void | setTitle(const QString &title) |
Member Function Documentation成员函数文档
QChart::QChart(QGraphicsItem *parent = 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.
构造一个图表对象,该对象是父级的子级。 由wFlags指定的属性将传递给QGraphicsWidget构造函数。
[virtual] 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.
将轴轴按对齐方式指定的对齐方式添加到图表中。 该图表获取轴的所有权。
See also 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.
注意:默认情况下,新添加的系列不会附加到任何轴,甚至不会在将系列添加到图表之前使用createDefaultAxes()为图表创建的轴。 如果在显示图表之前没有轴连接到新添加的系列,则该系列将被绘制,就好像它的轴的范围完全适合该系列与图表的绘图区域一样。 如果同一图表还显示其他具有正确连接的轴的序列,这可能会造成混淆,因此请始终确保在添加序列后调用createDefaultAxes()或显式附加序列的轴。
See also removeSeries(), removeAllSeries(), createDefaultAxes(), and QAbstractSeries::attachAxis().
QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 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.
返回以方向指定的方向连接到系列系列的轴。 如果未指定任何系列,则返回以指定方向添加到图表的所有轴。
See also addAxis() and createDefaultAxes().
QBrush QChart::backgroundBrush() const
Gets the brush that is used for painting the background of the chart area.
获取用于绘制图表区域背景的画笔。
See also setBackgroundBrush().
QPen QChart::backgroundPen() const
Gets the pen that is used for painting the background of the chart area.
获取用于绘制图表区域背景的笔。
See also 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 | Horizontal axis (X) | Vertical axis (Y) |
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.
如果在图表中添加了多个QXYSeries派生系列,而未添加其他类型的系列,则仅创建一对轴。 如果图表中添加了多个不同类型的序列,则每个序列都有自己的轴对。
通过将序列作为axis()函数调用的参数,可以稍后从图表中获得特定于该序列的轴。 QPieSeries不创建任何轴。
See also axes() and QAbstractSeries::attachAxis().
bool QChart::isZoomed()
Returns true if any series has a zoomed domain.如果任何系列具有缩放域,则返回true。
QLegend *QChart::legend() const
Returns the legend object of the chart. Ownership stays with the chart.返回图表的图例对象。 所有权与图表保持一致。
QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series = 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 = 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.
返回用于填充图表绘图区域背景的画笔。
See also plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), and setPlotAreaBackgroundBrush().
QPen QChart::plotAreaBackgroundPen() const
Returns the pen used to draw the background of the plot area of the chart.
返回用于绘制图表绘图区域背景的笔。
See also plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), and setPlotAreaBackgroundPen().
void QChart::removeAllSeries()
Removes and deletes all series objects that have been added to the chart.
删除并删除已添加到图表中的所有系列对象。
See also 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.
从图表中删除轴。 该图表将释放指定轴对象的所有权。
See also 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.
从图表中删除系列系列。 图表释放指定系列对象的所有权。
See also 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.
按dx和dy指定的距离滚动图表的可见区域。
对于极坐标图,dx表示沿角轴的角度而不是距离。
QList<QAbstractSeries *> QChart::series() const
Returns all series that are added to the chart.返回添加到图表的所有系列。
See also addSeries(), removeSeries(), and removeAllSeries().
void QChart::setBackgroundBrush(const QBrush &brush)
Sets the brush that is used for painting the background of the chart area to brush.
设置用于绘制图表区域背景的画笔。
See also backgroundBrush().
void QChart::setBackgroundPen(const QPen &pen)
Sets the pen that is used for painting the background of the chart area to pen.
将用于绘制图表区域背景的笔设置为pen。
See also backgroundPen().
void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
Sets the brush used to fill the background of the plot area of the chart to brush.
设置用于填充图表绘图区域背景的画笔。
See also 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.
将用于绘制图表绘图区域背景的笔设置为pen。
See also plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), and plotAreaBackgroundPen().
void QChart::setTitleBrush(const QBrush &brush)
Sets the brush used for drawing the title text to brush.
设置用于绘制标题文本的画笔。
See also titleBrush().
void QChart::setTitleFont(const QFont &font)
Sets the font that is used for drawing the chart title to font.
将用于绘制图表标题的字体设置为font。
See also titleFont().
QBrush QChart::titleBrush() const
Returns the brush used for drawing the title text.
See also setTitleBrush().
QFont QChart::titleFont() const
Gets the font that is used for drawing the chart title.
返回用于绘制标题文本的画笔。
See also 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.
通过自定义因子放大视图。
大于1.0的系数会放大视图,而0.0到1.0的系数会缩小视图。
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: Applying a zoom may modify properties of attached axes, for instance QAbstractAxis::min and QAbstractAxis::max.
Note: This is not supported for polar charts.
放大视图至最大程度,直到矩形矩形仍完全可见。
注意:应用缩放可能会修改附加轴的属性,例如QAbstractAxis :: min和QAbstractAxis :: max。
注意:极坐标图不支持此功能。
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.
将系列域重置为调用任何缩放方法之前的域。
注意:这还将重置在第一次缩放操作和调用此方法之间指定的滚动和显式轴范围设置。 如果未执行缩放操作,则此方法不执行任何操作。