Pie and doughnut charts are divided into segments, where the arc of each segment shows the proportion of each data.
In Chart.js, these two charts are essentially the same. The only different value is the cutoutPercentage. This dataset class will work for either pie or doughtnut charts interchangably
Create a Pie dataset with just a label
Create a Pie dataset with a label and data
Set the label for this dataset
Set the data displayed by this dataset This is a list of floats, where each float is represented as an arc
Set whether this dataset should be hidden from the chart
Set the drawing order of the dataset This also affects stacking, tooltips, and legends
Pie datasets are quite similar to bar dataset - provide a dataset label and a list of floats
defaultPieFromData "Example Chart" [ 4, 8, 15, 16, 23, 42 ]When grouping datasets into a chart data object, the labels specified will be used as the categories:
dataset =
defaultPieFromData "Example Chart" [ 4, 8, 15, 16, 23, 42 ]
|> ChartData.PieData
data =
ChartData.dataFromLabels [ "One", "Two", "Three", "Four", "Five", "Six" ]
|> ChartData.addDataset datasetThere are a wide variety of methods that can be used to adjust the shape of your pie chart. By setting a cutout value, a pie dataset will be transformed into a doughnut dataset.
defaultPieFromData "Example Chart" [ 4, 8, 15, 16, 23, 42 ]
|> setCutout 50To create an arc, set the circumference and initial rotation (both in degrees) to adjust the extents of the chart:
defaultPieFromData "Bottom Half Pie" [ 4, 8, 15, 16, 23, 42 ]
|> setCircumference 180
|> setRotation 90Total sweep, in degrees, to allow arcs to cover
Cutout, in pixels
Offset for each arc, in pixels
Starting angle, in degrees, to draw dataset from
The relative thickness of this dataset If specified, then this dataset will be drawn with a thickness relative to the sum of all dataset weights
Fill color of the arcs
Whether the borders of each arc should overlap or not Set to 'center' to overlap Set to 'inner' to not overlap
Color of the border
Width of the border
Fill color of the arcs when hovered
Border color of the arcs when hovered
Width of the border when hovered
For further information on these properties, see https://www.chartjs.org/docs/latest/charts/doughnut.html
You should not use the dataset type directly Instead use the updater pipeline functions: