This is the template sandbox page for Template:Piechart (diff). See also the companion subpage for test cases. |
This template uses Lua: |
This template uses TemplateStyles: |
See more examples here: Module:Piechart
Quick example with custom colors and a legend:
{{Piechart| [
{"label": "sweets: $v", "value": 5, "color":"darkred"},
{"label": "sandwiches: $v", "value": 3, "color":"wheat"},
{"label": "cookies: $v", "value": 2, "color":"goldenrod"},
{"label": "drinks: $v", "value": 1, "color":"#ccf"}
]
|meta={"autoscale":true, "legend":true}
}}
Use thumb=right for a floating image-like view. You can also add direction
option with one of column values to make the box thinner (like you see here).
{{Piechart| [
{"label": "sweets: $v", "value": 5, "color":"darkred"},
{"label": "sandwiches: $v", "value": 3, "color":"wheat"},
{"label": "cookies: $v", "value": 2, "color":"goldenrod"},
{"label": "drinks: $v", "value": 1, "color":"#ccf"}
]
|meta={
"autoscale":true,
"direction":"column-reverse",
"size":200,
"width":"min-content",
"legend":true
}
|thumb=right
|caption=What do you consume on b-day parties?
}}
Template to create pie charts (proportionally divided circle). Note that values can be an approximation and can be automatically scaled to 100%.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Chart data | 1 | JSON with items containing value, label, color (only value is required). Colors can be assigned automatically.
| String | required |
Options | meta | Additional metadata. Also in JSON. Possible options: size (chart size in px); autoscale (true to auto-calculate percentages); legend (default is false); direction (flex-like); width (css width of a container). See examples on Module:Piechart.
| String | suggested |
thumb | thumb | Float to left or to right ~like an image.
| Line | optional |
thumb-size | thumb-size | Box size in px. Remove to make the size change automatically (based on labels and graph size). | Number | optional |
caption | caption | Caption of the chart. Only really makes sense when used with thumb. | Line | optional |