Class: QgsLayoutItemChart

A layout item subclass that renders chart plots.

Added in version 4.0.

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.

Methods

plot

Returns the plot used to render the chart.

seriesList

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

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 wil be gathered from.

setSortExpression

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

setSortFeatures

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

setSourceLayer

Sets the source vector layer from which the plot data wil 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 wil be gathered from.

sortExpression

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

sortFeatures

Returns True if features should be sorted when iterating through the vector layer from which the plot data wil 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.

QgsLayoutItemChart.SeriesDetails(name: Optional[str] = ‘’) Constructor for SeriesDetails with an optional name parameter to provide a name string to the series.

QgsLayoutItemChart.SeriesDetails(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]

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]

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 wil 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 wil 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 wil 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 wil 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 wil 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 wil 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 wil 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]