Represent data with a pie chart
A pie chart is a special case of polar chart where the data values
are represented by the angle of the slices. They should only be used to
compare qualitatively proportions and compositions. Indeed, human eye is
not good at comparing angles so only large differences are visible.
Constructor
new Piechart(el, data, options)
| Name | Type | Description |
|---|---|---|
el |
string | CSS selector representing the element that will hold the chart. |
data |
Array.<number> | Data the chart has to represent. |
options |
PiechartOptions | Options controling graphical aspects of the chart. |
Options
-
Name Type Default Description widthnumber 60 Width of the chart. heightnumber 60 Height of the chart. transitionTimenumber 750 Duration of the transitions, in milliseconds. colorsArray.<string> | function d3.schemeCategory10 Either an array of colors or a function `(d, i) -> color` where `d` is a data value and `i` is the index of the value.If it is an array with length less than the length of data, then the colors are recycled. labelsArray.<string> | "none" | "auto" | function "none" Labels to display in slices. It can be an array with same length as the data. It can also be a function `(d, i) -> labelText` where `d` is a data value and `i` is the index of the value. Finally it can be equal to "none" to hide labels or "auto" to display in a compact way values. labelColorsstring | Array.<string> | "auto" | function "auto" Color of the labels. It can be a single value or an array with same length as the data. It can also be a function `(d, i) -> color` where `d` is a data value and `i` is the index of the value. Finally it can be equal to "auto". In this case, the most readable color is choosen depding on the color of the slice. labelMinSizenumber 8 Label minimum size in pixels. If there is not enough space for a given label, then it is hidden. labelMaxSizenumber 24 Label maximum size in pixels. labelClassstring "" Labels CSS class. shapeClassstring "" slices CSS class.
Methods
-
setData(data)
Update the data represented by the chartName Type Description dataArray.<number> Data the chart has to represent. -
setOptions(options)
Update the graphical options of a chartName Type Description optionsPiechartOptions Options controling graphical aspects of the chart. -
update(data, options)
Update simulatenously data and options of a pie chart.Name Type Description dataArray.<number> Data the chart has to represent. optionsPiechartOptions Options controling graphical aspects of the chart.