QChart 类管理图表系列、图例和轴的图形表示。 更多...
头: | #include <QChart> |
继承: | QGraphicsWidget |
继承者: | QPolarChart |
enum | AnimationOption { NoAnimation, GridAxisAnimations, SeriesAnimations, AllAnimations } |
flags | AnimationOptions |
enum | ChartTheme { ChartThemeLight, ChartThemeBlueCerulean, ChartThemeDark, ChartThemeBrownSand, ChartThemeBlueNcs, …, 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 | 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 = nullptr) |
QPointF | mapToValue (const QPointF & position , QAbstractSeries * series = 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 (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 | zoomReset () |
void | plotAreaChanged (const QRectF & plotArea ) |
QChart 是 QGraphicsWidget 可以展示在 QGraphicsScene 。它管理不同系列类型及其它图表相关对象 (像图例和轴) 的图形表示。为在布局中简单展示图表,方便类 QChartView 可以用来代替 QChart。此外,线、样条线、区域及散点系列,可以呈现成极坐标图表通过使用 QPolarChart 类。
另请参阅 QChartView and QPolarChart .
此枚举描述图表中启用的动画。
常量 | 值 | 描述 |
---|---|---|
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. |
AnimationOptions 类型是 typedef 对于 QFlags <AnimationOption>. It stores an OR combination of AnimationOption values.
此枚举描述用于图表的主题。
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 图表主题范例 illustrates how to use themes.
注意: Changing the theme will overwrite all customizations previously applied to the series.
常量 | 值 | 描述 |
---|---|---|
QChart::ChartThemeLight
|
0
|
The light theme, which is the default theme. |
QChart::ChartThemeBlueCerulean
|
1
|
钴天蓝主题。 |
QChart::ChartThemeDark
|
2
|
暗黑主题。 |
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
|
Qt 主题。 |
此枚举描述图表类型。
常量 | 值 | 描述 |
---|---|---|
QChart::ChartTypeUndefined
|
0
|
图表类型未定义。 |
QChart::ChartTypeCartesian
|
1
|
笛卡尔图表。 |
QChart::ChartTypePolar
|
2
|
极坐标图表。 |
This property holds the duration of the animation for the chart.
访问函数:
int | animationDuration () const |
void | setAnimationDuration (int msecs ) |
This property holds the easing curve of the animation for the chart.
访问函数:
QEasingCurve | animationEasingCurve () const |
void | setAnimationEasingCurve (const QEasingCurve & curve ) |
This property holds the animation options for the chart.
Animations are enabled or disabled based on this setting.
访问函数:
QChart::AnimationOptions | animationOptions () const |
void | setAnimationOptions (QChart::AnimationOptions options ) |
This property holds the diameter of the rounding circle at the corners of the chart background.
访问函数:
qreal | backgroundRoundness () const |
void | setBackgroundRoundness (qreal diameter ) |
此特性保持图表背景是否可见。
访问函数:
bool | isBackgroundVisible () const |
void | setBackgroundVisible (bool visible = true) |
另请参阅 setBackgroundBrush (), setBackgroundPen (),和 plotAreaBackgroundVisible .
[read-only]
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.
访问函数:
QChart::ChartType | chartType () const |
另请参阅 QPolarChart .
This property holds whether the background drop shadow effect is enabled.
若设为
true
, the background drop shadow effect is enabled. If set to
false
, it is disabled.
注意: 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) |
此特性保持用于格式各种图表标签的区域设置。
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 .
This property holds whether numbers are localized.
当
true
, all generated numbers appearing in various series and axis labels will be localized using the
QLocale
set with the
locale
property. When
false
,
C
locale is always used. Defaults to
false
.
注意: 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 .
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 ) |
此特性保持绘制图表内的矩形。
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.
访问函数:
QRectF | plotArea () const |
void | setPlotArea (const QRectF & rect ) |
通知程序信号:
void | plotAreaChanged (const QRectF & plotArea ) |
此特性保持图表绘图区域背景是否可见。
注意: 默认情况下,绘图区域背景是不可见的且绘图区域使用一般图表背景。
访问函数:
bool | isPlotAreaBackgroundVisible () const |
void | setPlotAreaBackgroundVisible (bool visible = true) |
另请参阅 setPlotAreaBackgroundBrush (), setPlotAreaBackgroundPen (),和 backgroundVisible .
此特性保持用于图表的主题。
访问函数:
QChart::ChartTheme | theme () const |
void | setTheme (QChart::ChartTheme theme ) |
此特性保持图表的标题。
标题是展示在图表顶部的标题行。图表标题支持 HTML 格式。
访问函数:
QString | title () const |
void | setTitle (const QString & title ) |
构造子级图表对象为 parent 。特性指定通过 wFlags 被传递给 QGraphicsWidget 构造函数。
[virtual]
QChart::
~QChart
()
删除图表对象及其子级,譬如:添加到它的系列和轴对象。
添加轴 axis 到图表对齐的指定通过 alignment 。图表拥有轴的所有权。
另请参阅 removeAxis (), createDefaultAxes (),和 QAbstractSeries::attachAxis ().
添加系列 series 到图表并拥有其所有权。
注意: 默认情况下,不会将新近添加的系列附加到任何轴,甚至图表可能已创建那些轴使用 createDefaultAxes () 在将系列添加到图表之前。若展示图表之前没有将轴附加到新近添加的系列,系列将被绘制,就好像它拥有会将系列范围准确拟合到图表绘图区域的轴。这会令人困惑,若同一图表还显示拥有正确附加轴的其它系列,因此始终确保调用 createDefaultAxes () 在添加系列后或为系列明确附加轴。
另请参阅 removeSeries (), removeAllSeries (), createDefaultAxes (),和 QAbstractSeries::attachAxis ().
返回轴已附加到系列 series 采用取向指定通过 orientation 。若未指定系列,按指定取向返回添加到图表的所有轴。
另请参阅 addAxis () 和 createDefaultAxes ().
Gets the brush that is used for painting the background of the chart area.
另请参阅 setBackgroundBrush ().
Gets the pen that is used for painting the background of the chart area.
另请参阅 setBackgroundPen ().
基于已添加到图表的系列为图表创建轴。先前添加到图表的任何轴都会被删除。
注意: 此函数必须被调用,在将所有系列添加到图表后。由此函数创建的轴不会自动附加到 (已添加到图表的) 任何系列,在此函数被调用后。默认情况下,将比例缩放没有附加轴的系列以利用图表的整个绘图区域,这会令人困惑,若还存在其它带有正确附加轴的系列。
系列类型 | 水平轴 (X) | 垂直轴 (Y) |
---|---|---|
QXYSeries | QValueAxis | QValueAxis |
QBarSeries | QBarCategoryAxis | QValueAxis |
QPieSeries | None | None |
若有几个 QXYSeries 派生系列被添加到图表且未添加其它类型的系列,则仅创建一对轴。若表有添加几个不同类型的系列,那么每个系列都有自己的轴对。
稍后可以从图表获得系列的特定轴,通过将系列提供作为参数对于 axes () 函数调用。 QPieSeries 不创建任何轴。
另请参阅 axes () 和 QAbstractSeries::attachAxis ().
返回
true
if any series has a zoomed domain.
返回图表的图例对象。所有权停留在图表。
Returns the position on the chart that corresponds to the value value in the series specified by series .
Returns the value in the series specified by series at the position specified by position in a chart.
Returns the brush used to fill the background of the plot area of the chart.
另请参阅 plotArea (), plotAreaBackgroundVisible , plotAreaBackgroundPen (),和 setPlotAreaBackgroundBrush ().
Returns the pen used to draw the background of the plot area of the chart.
另请参阅 plotArea (), plotAreaBackgroundVisible , plotAreaBackgroundBrush (),和 setPlotAreaBackgroundPen ().
Removes and deletes all series objects that have been added to the chart.
另请参阅 addSeries () 和 removeSeries ().
Removes the axis axis from the chart. The chart releases the ownership of the specified axis 对象。
另请参阅 addAxis (), createDefaultAxes (),和 QAbstractSeries::detachAxis ().
Removes the series series from the chart. The chart releases the ownership of the specified series 对象。
另请参阅 addSeries () 和 removeAllSeries ().
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.
Returns all series that are added to the chart.
另请参阅 addSeries (), removeSeries (),和 removeAllSeries ().
Sets the brush that is used for painting the background of the chart area to brush .
另请参阅 backgroundBrush ().
Sets the pen that is used for painting the background of the chart area to pen .
另请参阅 backgroundPen ().
Sets the brush used to fill the background of the plot area of the chart to brush .
另请参阅 plotArea (), plotAreaBackgroundVisible , setPlotAreaBackgroundPen (),和 plotAreaBackgroundBrush ().
Sets the pen used to draw the background of the plot area of the chart to pen .
另请参阅 plotArea (), plotAreaBackgroundVisible , setPlotAreaBackgroundBrush (),和 plotAreaBackgroundPen ().
Sets the brush used for drawing the title text to brush .
另请参阅 titleBrush ().
Sets the font that is used for drawing the chart title to font .
另请参阅 titleFont ().
Returns the brush used for drawing the title text.
另请参阅 setTitleBrush ().
Gets the font that is used for drawing the chart title.
另请参阅 setTitleFont ().
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.
Zooms into the view by a factor of two.
Zooms into the view to a maximum level at which the rectangle rect is still fully visible.
注意: Applying a zoom may modify properties of attached axes, for instance QAbstractAxis::min and QAbstractAxis::max.
注意: 这不支持极坐标图表。
Zooms out of the view by a factor of two.
注意: This will do nothing if the result would contain an invalid logarithmic axis range.
Resets the series domains to what they were before any zoom method was called.
注意: 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.