PieChart
Introduction
PieChart widget in Supervisely is a widget used for displaying a pie chart. It allows users to visualize data for comparison distribution of different objects. The PieChart widget allows easily visualize data to determine the distribution of objects in comparison to each other.
Function signature
Parameters
title
str
PieChart title
series
List[Dict[str, Union[int,float]]]
PieChart slices data
stroke_width
str
Gap between slices
data_labels
bool
Show value on slices
height
Union[int, str]
PieChart height size
type
Literal["pie", "donut"]
PieChart type. Can be pie or donut
title
Determines PieChart title.
type: str
series
PieChart slices data. The series should be a list of dicts with keys name and data. The name key should contain the name of the slice and the data key should contain the value of the slice.
type: List[Dict[str, Union[int,float]]]
default value: []
stroke_width
Determines the gap between slices on PieChart. Set to 0 to remove the gap.
type: int
default value: 2
data_labels
If True show values on PieChart slices. If False hide values on PieChart slices.
type: bool
default value: False
height
Determines the size of PieChart.
type: Union[int, str]
default value: 350
type
Determines the type of PieChart. Can be pie or donut.
type: Literal["pie", "donut"]
default value: pie
Methods and attributes
add_series(names: List[str], values: List[Union[int, float]])
Adds a new series to the PieChart widget.
set_series(names: List[str], values: List[Union[int, float]])
Sets a series to the PieChart widget, removing all previous series.
get_series(index: int))
Returns a series from the PieChart widget by index.
delete_series(index: int)
Deletes a series from the PieChart widget by index.
get_clicked_datapoint()
Returns the clicked datapoint from the PieChart widget as NamedTuple.
Mini app example
You can find this example in our GitHub repository:
supervisely-ecosystem/ui-widgets-demos/charts-and-plots/009_pie_chart/src/main.py
Import libraries
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
Initialize PieChart widget
Create GUI with buttons
Create app layout
Prepare a layout for the app using Card widget with the content parameter and place widget that we've just created in the Container widget.
Create an app using the layout
Create an app object with the layout parameter.
Using @click event
Add buttons logic: Add, Set, Remove
Last updated
Was this helpful?