Class: QgsLayoutItemChart

A layout item subclass that renders chart plots.

Added in version 4.0.

List of all members, including inherited members

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutItemChart

Base classes

QgsLayoutItem

Base class for graphical items within a QgsLayout.

QgsLayoutObject

A base class for objects which belong to a layout.

QObject

QgsExpressionContextGenerator

Abstract interface for generating an expression context.

QGraphicsRectItem

QAbstractGraphicsShapeItem

QGraphicsItem

QgsLayoutUndoObjectInterface

Interface for layout objects which support undo/redo commands.

Classes

SeriesDetails

Chart series details covering all supported series types.

Methods

filterOnlyVisibleFeatures

Returns True if the series are set to use only features visible on a corresponding map item.

filterToAtlasFeature

Returns True if the series are set to only show features which intersect the current atlas feature.

map

Returns the layout map to use to limit the series' use of features.

plot

Returns the plot used to render the chart.

seriesList

Returns the plot series details used to generate the plot data.

setFilterOnlyVisibleFeatures

Sets the series to only use features which are visible in a map item.

setFilterToAtlasFeature

Sets series to only use features which intersect the current atlas feature.

setMap

Sets a layout map to use to limit the series' use of features.

setPlot

Sets the plot used to render the chart.

setSeriesList

Sets the plot series details used to generate the plot data.

setSortAscending

Sets whether features should be sorted in an ascending order when iterating through the vector layer from which the plot data will be gathered from.

setSortExpression

Sets the expression used to sort features when iterating through the vector layer from which the plot data will be gathered from.

setSortFeatures

Sets whether features should be sorted when iterating through the vector layer from which the plot data will be gathered from.

setSourceLayer

Sets the source vector layer from which the plot data will be gathered from.

sortAscending

Returns True if features should be sorted in an ascending order when iterating through the vector layer from which the plot data will be gathered from.

sortExpression

Returns the expression used to sort features when iterating through the vector layer from which the plot data will be gathered from.

sortFeatures

Returns True if features should be sorted when iterating through the vector layer from which the plot data will be gathered from.

sourceLayer

Returns the source vector layer from which the plot data will be gathered from.

Static Methods

create

Returns a new chart item for the specified layout.

class qgis.core.QgsLayoutItemChart[source]

Bases: QgsLayoutItem

__init__(layout: QgsLayout | None)

Constructor for QgsLayoutItemChart, with the specified parent layout.

Parameters:

layout (Optional[QgsLayout])

class SeriesDetails[source]

Bases: object

Chart series details covering all supported series types.

Note

this class is experimental and therefore is not considered as stable API, it may change in the future as more chart plot types are implemented.

Added in version 4.0.

__init__(name: str | None = '')

Constructor for SeriesDetails with an optional name parameter to provide a name string to the series.

Parameters:

name (Optional[str] = '')

__init__(a0: QgsLayoutItemChart.SeriesDetails)
Parameters:

a0 (QgsLayoutItemChart.SeriesDetails)

filterExpression(self) str[source]

Returns the filter expression used to generate a series against a subset of the source layer.

Return type:

str

name(self) str[source]

Returns the series name.

Return type:

str

setFilterExpression(self, filterExpression: str | None)[source]

Sets the filter expression used to generate a series against a subset of the source layer.

Parameters:

filterExpression (Optional[str])

setName(self, name: str | None)[source]

Sets the series name.

Parameters:

name (Optional[str])

setXExpression(self, xExpression: str | None)[source]

Sets the expression used to generate X-axis values. If the associated chart X axis type is set to Qgis.PlotAxisType.Categorical, the generated values will be converted to strings. For Qgis.PlotAxisType.Interval, the generated values will be converted to double.

Parameters:

xExpression (Optional[str])

setYExpression(self, yExpression: str | None)[source]

Sets the expression used to generate Y-axis values. The generated values will be converted to double.

Parameters:

yExpression (Optional[str])

xExpression(self) str[source]

Returns the expression used to generate X-axis values. If the associated chart X axis type is set to Qgis.PlotAxisType.Categorical, the generated values will be converted to strings. For Qgis.PlotAxisType.Interval, the generated values will be converted to double.

Return type:

str

yExpression(self) str[source]

Returns the expression used to generate Y-axis values. The generated values will be converted to double.

Return type:

str

static create(layout: QgsLayout | None) QgsLayoutItemChart | None[source]

Returns a new chart item for the specified layout.

The caller takes responsibility for deleting the returned object.

Parameters:

layout (Optional[QgsLayout])

Return type:

Optional[QgsLayoutItemChart]

filterOnlyVisibleFeatures(self) bool[source]

Returns True if the series are set to use only features visible on a corresponding map item.

See also

map()

Return type:

bool

filterToAtlasFeature(self) bool[source]

Returns True if the series are set to only show features which intersect the current atlas feature.

Return type:

bool

map(self) QgsLayoutItemMap | None[source]

Returns the layout map to use to limit the series’ use of features. This setting only has an effect if setFilterOnlyVisibleFeatures is set to True.

See also

setMap()

Return type:

Optional[QgsLayoutItemMap]

plot(self) QgsPlot | None[source]

Returns the plot used to render the chart.

Return type:

Optional[QgsPlot]

seriesList(self) list[QgsLayoutItemChart.SeriesDetails]

Returns the plot series details used to generate the plot data.

See also

setSeriesList()

Return type:

list[QgsLayoutItemChart.SeriesDetails]

setFilterOnlyVisibleFeatures(self, visibleOnly: bool)[source]

Sets the series to only use features which are visible in a map item. Changing this setting forces the chart to refetch features from its vector layer.

See also

setMap()

Parameters:

visibleOnly (bool)

setFilterToAtlasFeature(self, filterToAtlas: bool)[source]

Sets series to only use features which intersect the current atlas feature.

Parameters:

filterToAtlas (bool)

setMap(self, map: QgsLayoutItemMap | None)[source]

Sets a layout map to use to limit the series’ use of features. This setting only has an effect if setFilterOnlyVisibleFeatures is set to True. Changing the map forces the chart to refetch features from its vector layer.

See also

map()

Parameters:

map (Optional[QgsLayoutItemMap])

setPlot(self, plot: QgsPlot | None)[source]

Sets the plot used to render the chart.

Ownership is transferred to the item.

Parameters:

plot (Optional[QgsPlot])

setSeriesList(self, seriesList: Iterable[QgsLayoutItemChart.SeriesDetails])[source]

Sets the plot series details used to generate the plot data.

See also

seriesList()

Parameters:

seriesList (Iterable[QgsLayoutItemChart.SeriesDetails])

setSortAscending(self, ascending: bool)[source]

Sets whether features should be sorted in an ascending order when iterating through the vector layer from which the plot data will be gathered from.

This property has no effect is sortFeatures() is False.

See also

sortAscending()

Parameters:

ascending (bool)

setSortExpression(self, expression: str | None)[source]

Sets the expression used to sort features when iterating through the vector layer from which the plot data will be gathered from.

See also

sortExpression()

Parameters:

expression (Optional[str])

setSortFeatures(self, sorted: bool)[source]

Sets whether features should be sorted when iterating through the vector layer from which the plot data will be gathered from.

See also

sortFeatures()

Parameters:

sorted (bool)

setSourceLayer(self, layer: QgsVectorLayer | None)[source]

Sets the source vector layer from which the plot data will be gathered from.

See also

sourceLayer()

Parameters:

layer (Optional[QgsVectorLayer])

sortAscending(self) bool[source]

Returns True if features should be sorted in an ascending order when iterating through the vector layer from which the plot data will be gathered from.

This property has no effect is sortFeatures() is False.

See also

sortFeatures()

See also

sortExpression()

Return type:

bool

sortExpression(self) str[source]

Returns the expression used to sort features when iterating through the vector layer from which the plot data will be gathered from.

See also

sortFeatures()

See also

sortAscending()

Return type:

str

sortFeatures(self) bool[source]

Returns True if features should be sorted when iterating through the vector layer from which the plot data will be gathered from.

See also

sortAscending()

See also

sortExpression()

Return type:

bool

sourceLayer(self) QgsVectorLayer | None[source]

Returns the source vector layer from which the plot data will be gathered from.

See also

setSourceLayer()

Return type:

Optional[QgsVectorLayer]