QChart Class▲
-
Header: QChart
-
Inherits: QGraphicsWidget
-
Inherited By: QPolarChart
Detailed Description▲
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.
See Also▲
See also QChartView, QPolarChart
Member Type Documentation▲
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.
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▲
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:
-
animationEasingCurve() const
-
void setAnimationEasingCurve(const &curve)
animationOptions : QChart::AnimationOptions▲
This property holds the animation options for the chart.
Animations are enabled or disabled based on this setting.
Access functions:
-
animationOptions() const
-
void setAnimationOptions( 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▲
See also 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.
Access functions:
-
chartType() const
See Also▲
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.
The drop shadow effect depends on the theme, and therefore the setting may change if the theme is changed.
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.
Access functions:
-
locale() const
-
void setLocale(const &locale)
See Also▲
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.
This property does not affect QDateTimeAxis labels, which always use the QLocale set with the locale property.
Access functions:
-
bool localizeNumbers() const
-
void setLocalizeNumbers(bool localize)
See Also▲
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:
-
margins() const
-
void setMargins(const &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.
Access functions:
-
plotArea() const
-
void setPlotArea(const &rect)
Notifier signal:
-
void plotAreaChanged(const &plotArea)
plotAreaBackgroundVisible : bool▲
This property holds whether the chart plot area background is visible.
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▲
See also setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
theme : QChart::ChartTheme▲
This property holds the theme used for the chart.
Access functions:
-
theme() const
-
void setTheme( 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.
Access functions:
-
title() const
-
void setTitle(const &title)
Member Function Documentation▲
[explicit] 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.
[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▲
See also removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
void QChart::addSeries(QAbstractSeries *series)▲
Adds the series series to the chart and takes ownership of it.
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.
See Also▲
See also removeSeries(), removeAllSeries(), createDefaultAxes(), 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▲
See also addAxis(), createDefaultAxes()
QBrush QChart::backgroundBrush() const▲
Gets the brush that is used for painting the background of the chart area.
See Also▲
See also setBackgroundBrush()
QPen QChart::backgroundPen() const▲
Gets the pen that is used for painting the background of the chart area.
See Also▲
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.
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.
See Also▲
See also axes(), 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 = 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▲
See also plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
QPen QChart::plotAreaBackgroundPen() const▲
Returns the pen used to draw the background of the plot area of the chart.
See Also▲
See also plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
void QChart::removeAllSeries()▲
Removes and deletes all series objects that have been added to the chart.
See Also▲
See also addSeries(), 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▲
See also addAxis(), createDefaultAxes(), 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▲
See also addSeries(), 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.
See Also▲
See also addSeries(), removeSeries(), 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▲
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.
See Also▲
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▲
See also plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
void QChart::setPlotAreaBackgroundPen(const QPen &pen)▲
Sets the pen used to draw the background of the plot area of the chart to pen.
See Also▲
See also plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
void QChart::setTitleBrush(const QBrush &brush)▲
void QChart::setTitleFont(const QFont &font)▲
QBrush QChart::titleBrush() const▲
QFont QChart::titleFont() const▲
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.
Applying a zoom may modify properties of attached axes, for instance QAbstractAxis::min and QAbstractAxis::max.
This is not supported for polar charts.
void QChart::zoomOut()▲
Zooms out of the view by a factor of two.
This will do nothing if the result would contain an invalid logarithmic axis range.
void QChart::zoomReset()▲
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.
Obsolete Members for QChart▲
The following members of class QChart are deprecated. We strongly advise against using them in new code.
Obsolete Member Function Documentation▲
QAbstractAxis *QChart::axisX(QAbstractSeries *series = nullptr) const▲
This function is deprecated. We strongly advise against using it in new code.
Use axes() instead.
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.
See Also▲
See also setAxisX(), addAxis(), QAbstractSeries::attachAxis()
QAbstractAxis *QChart::axisY(QAbstractSeries *series = nullptr) const▲
This function is deprecated. We strongly advise against using it in new code.
Use axes() instead.
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.
See Also▲
See also setAxisY(), addAxis(), QAbstractSeries::attachAxis()
void QChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series = nullptr)▲
This function is deprecated. We strongly advise against using it in new code.
Use addAxis() instead.
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.
See Also▲
See also axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
void QChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series = nullptr)▲
This function is deprecated. We strongly advise against using it in new code.
Use addAxis() instead.
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.
See Also▲
See also axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()