Skip to content

Pie Chart#

Pie #

Pie(
    data: Union[DataType, DataFrame],
    *,
    series: Optional[ChartSeries] = None,
    legend_position: LegendPosition = LegendPosition.BOTTOM,
    widget_id: Optional[str] = None,
    title: Optional[WidgetTitleType] = None,
    tooltips: Optional[TooltipItems] = None
)

Construct pie chart widget.

Construct a pie chart widget for visualizing data distribution, allowing customization of legends, tooltips, and series.

Constructor for Pie widget.

Parameters:

Name Type Description Default
data Union[DataType, DataFrame]

data for the widget. Can be a pandas dataframe or DataStorage object if the data is to be retrieved from a storage.

required
widget_id Optional[str]

unique widget id in a dashboard.

None
title Optional[WidgetTitleType]

title of widget can be either a string (fixed value) or determined by a value from another widget using a WidgetLink.

None
series Optional[ChartSeries]

Pie Series spec class.

None
legend_position LegendPosition

position of the legend within the pie.

BOTTOM
tooltips Optional[TooltipItems]

tooltip items to be displayed at Chart level.

None

Examples:#

Create a minimal Pie Widget
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import pie

data = pd.DataFrame(
    {
        "category": ["A", "B"],
        "value": [1, 2],
        "tooltip": ["X", "Y"],
    },
)

dashboard = Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=pie.Pie(data),
)
Set the legend position to right
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import pie

data = pd.DataFrame(
    {
        "category": ["A", "B"],
        "value": [1, 2],
        "tooltip": ["X", "Y"],
    },
)

dashboard = Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=pie.Pie(
        data=data,
        legend_position=pie.LegendPosition.RIGHT,
    ),
)

Category Series#

Series #

Series(
    *,
    name: TemplatedStringItem = "Series",
    category_column: TemplatedStringItem = "category",
    data_column: TemplatedStringItem = "value",
    formatting: Optional[NumberFormatting] = None,
    styling: Optional[Union[Palette, SeriesStyling]] = None,
    tooltips: Optional[TooltipItems] = None
)

Define pie chart series.

Define a generic series for the pie chart, specifying category and data columns, formatting, styling, and tooltips.

Constructor for Series.

Parameters:

Name Type Description Default
name TemplatedStringItem

name for the Pie series.

'Series'
category_column TemplatedStringItem

name of column in pandas dataframe(s) that has category info within the pie.

'category'
data_column TemplatedStringItem

name of column in pandas dataframe(s) that has pie data.

'value'
formatting Optional[NumberFormatting]

spec for number formatting.

None
styling Optional[Union[Palette, SeriesStyling]]

spec for pie series styling.

None
tooltips Optional[TooltipItems]

tooltip items to be displayed at Series level.

None

Examples:#

Customise Pie Widget series (e.g. changing data column)
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import pie

data = pd.DataFrame(
    {
        "name": ["X", "Y"],
        "volume": [10, 20],
    },
)
dashboard = Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=pie.Pie(
        data=data,
        series=pie.Series(
            category_column="name",
            data_column="volume",
        ),
    ),
)

CountrySeries #

CountrySeries(
    *,
    name: TemplatedStringItem = "Country Series",
    country_column: TemplatedStringItem = "country_code",
    data_column: TemplatedStringItem = "value",
    formatting: Optional[NumberFormatting] = None,
    styling: Optional[Union[Palette, SeriesStyling]] = None,
    tooltips: Optional[TooltipItems] = None
)

Define country-based pie chart series.

Define a series specifically for pie charts representing data categorized by country, with options for customizing country code column, data column, formatting, styling, and tooltips.

Constructor for CountrySeries.

Parameters:

Name Type Description Default
name TemplatedStringItem

name for the Pie series.

'Country Series'
country_column TemplatedStringItem

name of column in pandas dataframe(s) that has country code within the pie.

'country_code'
data_column TemplatedStringItem

name of column in pandas dataframe(s) that has pie data.

'value'
formatting Optional[NumberFormatting]

spec for number formatting.

None
styling Optional[Union[Palette, SeriesStyling]]

spec for pie series styling.

None
tooltips Optional[TooltipItems]

tooltip items to be displayed at Series level.

None

Examples:#

Create Pie Widget using a CountrySeries
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.widgets import pie

data = pd.DataFrame(
    {
        "country": ["US", "FR"],
        "volume": [10, 20],
    },
)
dashboard = Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=pie.Pie(
        data=data,
        series=pie.CountrySeries(
            country_column="name",
            data_column="volume",
        ),
    ),
)

SeriesStyling #

SeriesStyling(
    color_spec: Optional[ColorSpec] = None,
    data_column: Optional[TemplatedStringItem] = None,
)

Style pie chart series.

Specify styling options for pie chart series, including color specifications and data column mapping.

Constructor for SeriesStyling.

Parameters:

Name Type Description Default
color_spec Optional[ColorSpec]

specs for color.

None
data_column Optional[TemplatedStringItem]

name of column in pandas dataframe(s) that has the styling value.

None

Examples:#

Change color of Pie Widget series
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.styling import color
from engineai.sdk.dashboard.widgets import pie

data = pd.DataFrame(
    {
        "category": ["A", "B"],
        "value": [1, 2],
    },
)
dashboard = Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=pie.Pie(
        data=data,
        series=pie.Series(
            styling=pie.SeriesStyling(
                color_spec=color.Palette.BANANA_YELLOW,
            )
        ),
    ),
)
Coloring Pie Widget segments using a discrete color mapping
import pandas as pd
from engineai.sdk.dashboard.dashboard import Dashboard
from engineai.sdk.dashboard.styling import color
from engineai.sdk.dashboard.widgets import pie

data = pd.DataFrame(
    {
        "category": ["A", "B"],
        "value": [1, 2],
    },
)

dashboard = Dashboard(
    app_slug="engineai-docs-steps",
    workspace_slug="engineai-docs-steps",
    content=pie.Pie(
        data=data,
        series=pie.Series(
            styling=pie.SeriesStyling(
                color_spec=color.DiscreteMap(
                    color.DiscreteMapValueItem(
                        value=1,
                        color=color.Palette.BANANA_YELLOW,
                    ),
                    color.DiscreteMapValueItem(
                        value=2,
                        color=color.Palette.RUBI_RED,
                    ),
                ),
                data_column="value",
            )
        ),
    ),
)

Tooltips#

TextTooltipItem #

TextTooltipItem(
    *,
    data_column: TemplatedStringItem,
    formatting: Optional[TextFormatting] = None,
    label: Optional[Union[str, DataField]] = None
)

Customize tooltips for textual data in Chart.

Define specifications for a text item within a tooltip for a Chart widget to customize the appearance and content of tooltips displayed for textual data.

Constructor for TextTooltipItem.

Parameters:

Name Type Description Default
data_column TemplatedStringItem

name of column in pandas dataframe(s) used for the value of the tooltip item.

required
formatting Optional[TextFormatting]

tooltip formatting spec. Defaults to TextFormatting(max_characters=30).

None
label Optional[Union[str, DataField]]

label to be used for tooltip item, it can be either a string or a DataField object.

None

NumberTooltipItem #

NumberTooltipItem(
    *,
    data_column: TemplatedStringItem,
    formatting: Optional[NumberFormatting] = None,
    label: Optional[Union[str, DataField]] = None
)

Customize tooltips for numerical data in Chart.

Define specifications for a number item within a tooltip for a Chart widget to customize the appearance and content of tooltips displayed for numerical data.

Constructor for NumberTooltipItem.

Parameters:

Name Type Description Default
data_column TemplatedStringItem

name of column in pandas dataframe(s) used for the value of the tooltip item.

required
formatting Optional[NumberFormatting]

tooltip formatting spec. Defaults to None (Base NumberFormatting).

None
label Optional[Union[str, DataField]]

label to be used for tooltip item, it can be either a string or a DataField object.

None

CategoryTooltipItem #

CategoryTooltipItem(
    *,
    data_column: TemplatedStringItem,
    formatting: MapperFormatting,
    label: Optional[Union[str, DataField]] = None
)

Customize tooltips for categorical data in Chart widget.

Define specifications for a category tooltip item within a Chart widget to customize the appearance and content of tooltips displayed for categorical data.

Constructor for CategoryTooltipItem.

Parameters:

Name Type Description Default
data_column TemplatedStringItem

name of column in pandas dataframe(s) used for the value of the tooltip item.

required
formatting MapperFormatting

tooltip formatting spec.

required
label Optional[Union[str, DataField]]

label to be used for tooltip item, it can be either a string or a DataField object.

None

DatetimeTooltipItem #

DatetimeTooltipItem(
    *,
    data_column: TemplatedStringItem,
    formatting: Optional[DateTimeFormatting] = None,
    label: Optional[Union[str, DataField]] = None
)

Customize tooltips for datetime data in Chart.

Define specifications for a datetime item within a tooltip for a Chart widget to customize the appearance and content of tooltips displayed for datetime data.

Constructor for DatetimeTooltipItem.

Parameters:

Name Type Description Default
data_column TemplatedStringItem

name of column in pandas dataframe(s) used for the value of the tooltip item.

required
formatting DateTimeFormatting

tooltip formatting spec Defaults to DateTimeFormatting for Dates (i.e. not include HH:MM).

None
label Optional[Union[str, DataField]]

label to be used for tooltip item, it can be either a string or a DataField object.

None

Enums#

LegendPosition #

Legend position options.

Options for positioning the legend on the pie chart, including right, bottom, and next to the data.

Attributes:

Name Type Description
RIGHT

Legend is placed on the right side of the chart.

BOTTOM

Legend is placed on the bottom of the chart.

NEXT_TO_DATA

Legend is placed next to the data.