Class: QgsDiagram

Base class for all diagram types.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), diagramName(), diagramSize(), legendSize(), renderDiagram()

Class Hierarchy

Inheritance diagram of qgis.core.QgsDiagram

Subclasses

QgsHistogramDiagram

A histogram style diagram.

QgsPieDiagram

A pie chart diagram.

QgsStackedBarDiagram

A stacked bar chart diagram.

QgsStackedDiagram

A diagram composed of several subdiagrams, located side by side.

QgsTextDiagram

A text based diagram.

Abstract Methods

clone

Returns an instance that is equivalent to this one

diagramName

Gets a descriptive name for this diagram type.

diagramSize

Returns the size in map units the diagram will use to render.

legendSize

Returns the size of the legend item for the diagram corresponding to a specified value.

renderDiagram

Draws the diagram at the given position (in pixel coordinates)

Methods

clearCache

getExpression

Returns a prepared expression for the specified context.

scaledFont

Calculates a size to match the current settings and rendering context

setPenWidth

Changes the pen width to match the current settings and rendering context

sizeForValue

Returns the scaled size of a diagram for a value, respecting the specified diagram interpolation settings.

sizePainterUnits

Calculates a size to match the current settings and rendering context

class qgis.core.QgsDiagram[source]

Bases: object

clearCache(self)[source]
abstract clone(self) QgsDiagram | None[source]

Returns an instance that is equivalent to this one

Return type:

Optional[QgsDiagram]

abstract diagramName(self) str[source]

Gets a descriptive name for this diagram type.

Return type:

str

abstract diagramSize(self, attributes: Any, c: QgsRenderContext, s: QgsDiagramSettings) QSizeF[source]

Returns the size in map units the diagram will use to render.

Parameters:
Return type:

QSizeF

abstract diagramSize(self, feature: QgsFeature, c: QgsRenderContext, s: QgsDiagramSettings, interpolationSettings: QgsDiagramInterpolationSettings) QSizeF[source]

Returns the size in map units the diagram will use to render. Interpolate size

Parameters:
Return type:

QSizeF

getExpression(self, expression: str | None, context: QgsExpressionContext) QgsExpression | None[source]

Returns a prepared expression for the specified context.

Parameters:
  • expression (Optional[str]) – expression string

  • context (QgsExpressionContext) – expression context

Return type:

Optional[QgsExpression]

abstract legendSize(self, value: float, s: QgsDiagramSettings, interpolationSettings: QgsDiagramInterpolationSettings) float[source]

Returns the size of the legend item for the diagram corresponding to a specified value.

Parameters:
Return type:

float

abstract renderDiagram(self, feature: QgsFeature, c: QgsRenderContext, s: QgsDiagramSettings, position: QPointF | QPoint)[source]

Draws the diagram at the given position (in pixel coordinates)

Parameters:
scaledFont(self, s: QgsDiagramSettings, c: QgsRenderContext) QFont[source]

Calculates a size to match the current settings and rendering context

Parameters:
  • s (QgsDiagramSettings) – The settings that contain the font size and size type

  • c (QgsRenderContext) – The rendering specifying the proper scale units for pixel conversion

Return type:

QFont

Returns:

The properly scaled font for rendering

setPenWidth(self, pen: QPen | QColor | Qt.GlobalColor, s: QgsDiagramSettings, c: QgsRenderContext)[source]

Changes the pen width to match the current settings and rendering context

Parameters:
  • pen (Union[QPen, Union[QColor, Qt.GlobalColor]]) – The pen to modify

  • s (QgsDiagramSettings) – The settings that specify the pen width

  • c (QgsRenderContext) – The rendering specifying the proper scale units for pixel conversion

sizeForValue(self, value: float, s: QgsDiagramSettings, interpolationSettings: QgsDiagramInterpolationSettings) QSizeF[source]

Returns the scaled size of a diagram for a value, respecting the specified diagram interpolation settings.

Parameters:
Return type:

QSizeF

sizePainterUnits(self, size: QSizeF, s: QgsDiagramSettings, c: QgsRenderContext) QSizeF[source]

Calculates a size to match the current settings and rendering context

Parameters:
  • size (QSizeF) – The size to convert

  • s (QgsDiagramSettings) – The settings that specify the size type

  • c (QgsRenderContext) – The rendering specifying the proper scale units for pixel conversion

Return type:

QSizeF

Returns:

The converted size for rendering

sizePainterUnits(self, l: float, s: QgsDiagramSettings, c: QgsRenderContext) float[source]

Calculates a length to match the current settings and rendering context

Parameters:
  • l (float) – The length to convert

  • s (QgsDiagramSettings) – The settings that specify the size type

  • c (QgsRenderContext) – The rendering specifying the proper scale units for pixel conversion

Return type:

float

Returns:

The converted length for rendering