class 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#

Methods#

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

class 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 Charts with Widgets Gallery 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.

class 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.

Note

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

property animationDurationᅟ: int#

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

Access functions:
property animationEasingCurveᅟ: QEasingCurve#

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

Access functions:
property animationOptionsᅟ: Combination of QChart.AnimationOption#

This property holds The animation options for the chart..

Animations are enabled or disabled based on this setting.

Access functions:
property backgroundRoundnessᅟ: float#

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

Access functions:
property backgroundVisibleᅟ: bool#

This property holds Whether the chart background is visible..

See also

setBackgroundBrush() setBackgroundPen() plotAreaBackgroundVisible

Access functions:
property chartTypeᅟ: 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.

See also

QPolarChart

Access functions:
property 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 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.

See also

localizeNumbers

Access functions:
property 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 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:
property 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:
property 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 themeᅟ: QChart.ChartTheme#

This property holds The theme used for the chart..

Access functions:
property 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:
__init__([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.

__init__(type, parent, wFlags)
Parameters:
animationDuration()#
Return type:

int

Getter of property animationDurationᅟ .

animationEasingCurve()#
Return type:

QEasingCurve

Getter of property animationEasingCurveᅟ .

animationOptions()#
Return type:

Combination of AnimationOption

Getter of property animationOptionsᅟ .

backgroundBrush()#
Return type:

QBrush

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

backgroundPen()#
Return type:

QPen

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

backgroundRoundness()#
Return type:

float

Getter of property backgroundRoundnessᅟ .

chartType()#
Return type:

ChartType

Getter of property chartTypeᅟ .

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()

isBackgroundVisible()#
Return type:

bool

Getter of property backgroundVisibleᅟ .

isDropShadowEnabled()#
Return type:

bool

Getter of property dropShadowEnabledᅟ .

isPlotAreaBackgroundVisible()#
Return type:

bool

Getter of property plotAreaBackgroundVisibleᅟ .

isZoomed()#
Return type:

bool

Returns true if any series has a zoomed domain.

legend()#
Return type:

QLegend

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

locale()#
Return type:

QLocale

See also

setLocale()

Getter of property localeᅟ .

localizeNumbers()#
Return type:

bool

Getter of property localizeNumbersᅟ .

mapToPosition(value)#
Parameters:

valueQPointF

Return type:

QPointF

mapToValue(position)#
Parameters:

positionQPointF

Return type:

QPointF

margins()#
Return type:

QMargins

See also

setMargins()

Getter of property marginsᅟ .

plotArea()#
Return type:

QRectF

See also

setPlotArea()

Getter of property plotAreaᅟ .

plotAreaBackgroundBrush()#
Return type:

QBrush

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

plotAreaBackgroundPen()#
Return type:

QPen

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

plotAreaChanged(plotArea)#
Parameters:

plotAreaQRectF

Notification signal of property plotAreaᅟ .

removeAllSeries()#

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

See also

addSeries() removeSeries()

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.

setAnimationDuration(msecs)#
Parameters:

msecs – int

Setter of property animationDurationᅟ .

setAnimationEasingCurve(curve)#
Parameters:

curveQEasingCurve

Setter of property animationEasingCurveᅟ .

setAnimationOptions(options)#
Parameters:

options – Combination of AnimationOption

Setter of property animationOptionsᅟ .

setBackgroundBrush(brush)#
Parameters:

brushQBrush

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

setBackgroundPen(pen)#
Parameters:

penQPen

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

See also

backgroundPen()

setBackgroundRoundness(diameter)#
Parameters:

diameter – float

Setter of property backgroundRoundnessᅟ .

setBackgroundVisible([visible=true])#
Parameters:

visible – bool

Setter of property backgroundVisibleᅟ .

setDropShadowEnabled([enabled=true])#
Parameters:

enabled – bool

Setter of property dropShadowEnabledᅟ .

setLocale(locale)#
Parameters:

localeQLocale

See also

locale()

Setter of property localeᅟ .

setLocalizeNumbers(localize)#
Parameters:

localize – bool

Setter of property localizeNumbersᅟ .

setMargins(margins)#
Parameters:

marginsQMargins

See also

margins()

Setter of property marginsᅟ .

setPlotArea(rect)#
Parameters:

rectQRectF

See also

plotArea()

Setter of property plotAreaᅟ .

setPlotAreaBackgroundBrush(brush)#
Parameters:

brushQBrush

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

setPlotAreaBackgroundPen(pen)#
Parameters:

penQPen

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

setPlotAreaBackgroundVisible([visible=true])#
Parameters:

visible – bool

Setter of property plotAreaBackgroundVisibleᅟ .

setTheme(theme)#
Parameters:

themeChartTheme

See also

theme()

Setter of property themeᅟ .

setTitle(title)#
Parameters:

title – str

See also

title()

Setter of property titleᅟ .

setTitleBrush(brush)#
Parameters:

brushQBrush

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

See also

titleBrush()

setTitleFont(font)#
Parameters:

fontQFont

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

See also

titleFont()

theme()#
Return type:

ChartTheme

See also

setTheme()

Getter of property themeᅟ .

title()#
Return type:

str

See also

setTitle()

Getter of property titleᅟ .

titleBrush()#
Return type:

QBrush

Returns the brush used for drawing the title text.

See also

setTitleBrush()

titleFont()#
Return type:

QFont

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

See also

setTitleFont()

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.

zoomIn()#

Zooms into the view by a factor of two.

zoomIn(rect)
Parameters:

rectQRectF

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.

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.

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.