QChart#

The QChart class manages the graphical representation of the chart’s series, legends, and axes. More

Inheritance diagram of PySide6.QtCharts.QChart

Inherited by: QPolarChart

Synopsis#

Properties#

Functions#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

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.

class PySide6.QtCharts.QChart(type, parent, wFlags)#

PySide6.QtCharts.QChart([parent=None[, wFlags=Qt.WindowFlags()]])

Parameters:

Constructs a chart object that is a child of parent. The properties specified by wFlags are passed to the QGraphicsWidget constructor.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtCharts.QChart.animationDuration: int#

This property holds The duration of the animation for the chart..

Access functions:
property PᅟySide6.QtCharts.QChart.animationEasingCurve: PySide6.QtCore.QEasingCurve#

This property holds The easing curve of the animation for the chart..

Access functions:
property PᅟySide6.QtCharts.QChart.animationOptions: AnimationOptions#

This property holds The animation options for the chart..

Animations are enabled or disabled based on this setting.

Access functions:
property PᅟySide6.QtCharts.QChart.backgroundRoundness: float#

This property holds The diameter of the rounding circle at the corners of the chart background..

Access functions:
property PᅟySide6.QtCharts.QChart.backgroundVisible: bool#

This property holds Whether the chart background is visible..

See also

setBackgroundBrush() setBackgroundPen() plotAreaBackgroundVisible

Access functions:
property PᅟySide6.QtCharts.QChart.chartType: 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.

See also

QPolarChart

Access functions:
property PᅟySide6.QtCharts.QChart.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.

Access functions:
property PᅟySide6.QtCharts.QChart.locale: PySide6.QtCore.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.

See also

localizeNumbers

Access functions:
property PᅟySide6.QtCharts.QChart.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.

See also

locale

Access functions:
property PᅟySide6.QtCharts.QChart.margins: PySide6.QtCore.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:
property PᅟySide6.QtCharts.QChart.plotArea: PySide6.QtCore.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:
property PᅟySide6.QtCharts.QChart.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:
property PᅟySide6.QtCharts.QChart.theme: ChartTheme#

This property holds The theme used for the chart..

Access functions:
property PᅟySide6.QtCharts.QChart.title: str#

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:
PySide6.QtCharts.QChart.ChartType#

This enum describes the chart type.

Constant

Description

QChart.ChartTypeUndefined

The chart type is not defined.

QChart.ChartTypeCartesian

A cartesian chart.

QChart.ChartTypePolar

A polar chart.

PySide6.QtCharts.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

Description

QChart.ChartThemeLight

The light theme, which is the default theme.

QChart.ChartThemeBlueCerulean

The cerulean blue theme.

QChart.ChartThemeDark

The dark theme.

QChart.ChartThemeBrownSand

The sand brown theme.

QChart.ChartThemeBlueNcs

The natural color system (NCS) blue theme.

QChart.ChartThemeHighContrast

The high contrast theme.

QChart.ChartThemeBlueIcy

The icy blue theme.

QChart.ChartThemeQt

The Qt theme.

PySide6.QtCharts.QChart.AnimationOption#

(inherits enum.Flag) This enum describes the animations enabled in the chart.

Constant

Description

QChart.NoAnimation

Animation is disabled in the chart. This is the default value.

QChart.GridAxisAnimations

Grid axis animation is enabled in the chart.

QChart.SeriesAnimations

Series animation is enabled in the chart.

QChart.AllAnimations

All animation types are enabled in the chart.

PySide6.QtCharts.QChart.addAxis(axis, alignment)#
Parameters:

Adds the axis axis to the chart aligned as specified by alignment. The chart takes the ownership of the axis.

PySide6.QtCharts.QChart.addSeries(series)#
Parameters:

seriesPySide6.QtCharts.QAbstractSeries

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.

PySide6.QtCharts.QChart.animationDuration()#
Return type:

int

Getter of property animationDuration .

PySide6.QtCharts.QChart.animationEasingCurve()#
Return type:

PySide6.QtCore.QEasingCurve

Getter of property animationEasingCurve .

PySide6.QtCharts.QChart.animationOptions()#
Return type:

AnimationOptions

Getter of property animationOptions .

PySide6.QtCharts.QChart.axes([orientation=Qt.Horizontal|Qt.Vertical[, series=None]])#
Parameters:
Return type:

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.

PySide6.QtCharts.QChart.axisX([series=None])#
Parameters:

seriesPySide6.QtCharts.QAbstractSeries

Return type:

PySide6.QtCharts.QAbstractAxis

Note

This function is deprecated.

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.

PySide6.QtCharts.QChart.axisY([series=None])#
Parameters:

seriesPySide6.QtCharts.QAbstractSeries

Return type:

PySide6.QtCharts.QAbstractAxis

Note

This function is deprecated.

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.

PySide6.QtCharts.QChart.backgroundBrush()#
Return type:

PySide6.QtGui.QBrush

Gets the brush that is used for painting the background of the chart area.

PySide6.QtCharts.QChart.backgroundPen()#
Return type:

PySide6.QtGui.QPen

Gets the pen that is used for painting the background of the chart area.

PySide6.QtCharts.QChart.backgroundRoundness()#
Return type:

float

Getter of property backgroundRoundness .

PySide6.QtCharts.QChart.chartType()#
Return type:

ChartType

Getter of property chartType .

PySide6.QtCharts.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)

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.

See also

axes() attachAxis()

PySide6.QtCharts.QChart.isBackgroundVisible()#
Return type:

bool

Getter of property backgroundVisible .

PySide6.QtCharts.QChart.isDropShadowEnabled()#
Return type:

bool

Getter of property dropShadowEnabled .

PySide6.QtCharts.QChart.isPlotAreaBackgroundVisible()#
Return type:

bool

Getter of property plotAreaBackgroundVisible .

PySide6.QtCharts.QChart.isZoomed()#
Return type:

bool

Returns true if any series has a zoomed domain.

PySide6.QtCharts.QChart.legend()#
Return type:

PySide6.QtCharts.QLegend

Returns the legend object of the chart. Ownership stays with the chart.

PySide6.QtCharts.QChart.locale()#
Return type:

PySide6.QtCore.QLocale

See also

setLocale()

Getter of property locale .

PySide6.QtCharts.QChart.localizeNumbers()#
Return type:

bool

Getter of property localizeNumbers .

PySide6.QtCharts.QChart.mapToPosition(value[, series=None])#
Parameters:
Return type:

PySide6.QtCore.QPointF

Returns the position on the chart that corresponds to the value value in the series specified by series.

PySide6.QtCharts.QChart.mapToValue(position[, series=None])#
Parameters:
Return type:

PySide6.QtCore.QPointF

Returns the value in the series specified by series at the position specified by position in a chart.

PySide6.QtCharts.QChart.margins()#
Return type:

PySide6.QtCore.QMargins

See also

setMargins()

Getter of property margins .

PySide6.QtCharts.QChart.plotArea()#
Return type:

PySide6.QtCore.QRectF

See also

setPlotArea()

Getter of property plotArea .

PySide6.QtCharts.QChart.plotAreaBackgroundBrush()#
Return type:

PySide6.QtGui.QBrush

Returns the brush used to fill the background of the plot area of the chart.

PySide6.QtCharts.QChart.plotAreaBackgroundPen()#
Return type:

PySide6.QtGui.QPen

Returns the pen used to draw the background of the plot area of the chart.

PySide6.QtCharts.QChart.plotAreaChanged(plotArea)#
Parameters:

plotAreaPySide6.QtCore.QRectF

Notification signal of property plotArea .

PySide6.QtCharts.QChart.removeAllSeries()#

Removes and deletes all series objects that have been added to the chart.

PySide6.QtCharts.QChart.removeAxis(axis)#
Parameters:

axisPySide6.QtCharts.QAbstractAxis

Removes the axis axis from the chart. The chart releases the ownership of the specified axis object.

PySide6.QtCharts.QChart.removeSeries(series)#
Parameters:

seriesPySide6.QtCharts.QAbstractSeries

Removes the series series from the chart. The chart releases the ownership of the specified series object.

PySide6.QtCharts.QChart.scroll(dx, dy)#
Parameters:
  • dx – float

  • dy – float

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.

PySide6.QtCharts.QChart.series()#
Return type:

Returns all series that are added to the chart.

PySide6.QtCharts.QChart.setAnimationDuration(msecs)#
Parameters:

msecs – int

Setter of property animationDuration .

PySide6.QtCharts.QChart.setAnimationEasingCurve(curve)#
Parameters:

curvePySide6.QtCore.QEasingCurve

Setter of property animationEasingCurve .

PySide6.QtCharts.QChart.setAnimationOptions(options)#
Parameters:

optionsAnimationOptions

Setter of property animationOptions .

PySide6.QtCharts.QChart.setAxisX(axis[, series=None])#
Parameters:

Note

This function is deprecated.

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.

PySide6.QtCharts.QChart.setAxisY(axis[, series=None])#
Parameters:

Note

This function is deprecated.

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.

PySide6.QtCharts.QChart.setBackgroundBrush(brush)#
Parameters:

brushPySide6.QtGui.QBrush

Sets the brush that is used for painting the background of the chart area to brush.

PySide6.QtCharts.QChart.setBackgroundPen(pen)#
Parameters:

penPySide6.QtGui.QPen

Sets the pen that is used for painting the background of the chart area to pen.

See also

backgroundPen()

PySide6.QtCharts.QChart.setBackgroundRoundness(diameter)#
Parameters:

diameter – float

Setter of property backgroundRoundness .

PySide6.QtCharts.QChart.setBackgroundVisible([visible=true])#
Parameters:

visible – bool

Setter of property backgroundVisible .

PySide6.QtCharts.QChart.setDropShadowEnabled([enabled=true])#
Parameters:

enabled – bool

Setter of property dropShadowEnabled .

PySide6.QtCharts.QChart.setLocale(locale)#
Parameters:

localePySide6.QtCore.QLocale

See also

locale()

Setter of property locale .

PySide6.QtCharts.QChart.setLocalizeNumbers(localize)#
Parameters:

localize – bool

Setter of property localizeNumbers .

PySide6.QtCharts.QChart.setMargins(margins)#
Parameters:

marginsPySide6.QtCore.QMargins

See also

margins()

Setter of property margins .

PySide6.QtCharts.QChart.setPlotArea(rect)#
Parameters:

rectPySide6.QtCore.QRectF

See also

plotArea()

Setter of property plotArea .

PySide6.QtCharts.QChart.setPlotAreaBackgroundBrush(brush)#
Parameters:

brushPySide6.QtGui.QBrush

Sets the brush used to fill the background of the plot area of the chart to brush.

PySide6.QtCharts.QChart.setPlotAreaBackgroundPen(pen)#
Parameters:

penPySide6.QtGui.QPen

Sets the pen used to draw the background of the plot area of the chart to pen.

PySide6.QtCharts.QChart.setPlotAreaBackgroundVisible([visible=true])#
Parameters:

visible – bool

Setter of property plotAreaBackgroundVisible .

PySide6.QtCharts.QChart.setTheme(theme)#
Parameters:

themeChartTheme

See also

theme()

Setter of property theme .

PySide6.QtCharts.QChart.setTitle(title)#
Parameters:

title – str

See also

title()

Setter of property title .

PySide6.QtCharts.QChart.setTitleBrush(brush)#
Parameters:

brushPySide6.QtGui.QBrush

Sets the brush used for drawing the title text to brush.

See also

titleBrush()

PySide6.QtCharts.QChart.setTitleFont(font)#
Parameters:

fontPySide6.QtGui.QFont

Sets the font that is used for drawing the chart title to font.

See also

titleFont()

PySide6.QtCharts.QChart.theme()#
Return type:

ChartTheme

See also

setTheme()

Getter of property theme .

PySide6.QtCharts.QChart.title()#
Return type:

str

See also

setTitle()

Getter of property title .

PySide6.QtCharts.QChart.titleBrush()#
Return type:

PySide6.QtGui.QBrush

Returns the brush used for drawing the title text.

See also

setTitleBrush()

PySide6.QtCharts.QChart.titleFont()#
Return type:

PySide6.QtGui.QFont

Gets the font that is used for drawing the chart title.

See also

setTitleFont()

PySide6.QtCharts.QChart.zoom(factor)#
Parameters:

factor – float

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.

PySide6.QtCharts.QChart.zoomIn()#

Zooms into the view by a factor of two.

PySide6.QtCharts.QChart.zoomIn(rect)
Parameters:

rectPySide6.QtCore.QRectF

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.

PySide6.QtCharts.QChart.zoomOut()#

Zooms out of the view by a factor of two.

Note

This will do nothing if the result would contain an invalid logarithmic axis range.

PySide6.QtCharts.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.