This is a little javascript demo to label segments of a pie chart with anchor lines based on the popular Chart.js library.
The plugin is not a 'real' npm plugin yet. You can just copy the code into your javascript code and add the plugin to your chart's plugin list:
const config = {
type: 'pie',
data: data,
options: options,
plugins: [chartLineLabelPlugin, ...]
};There are several properties you can set to change the appearance of the labels.
const options = {
...
plugins: {
chartLineLabelPlugin: {
labelSpace: 120,
lineHeightFactor: 1.2,
anchorCenterPercent: 100,
font: "12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
color: 'gray',
edgePadding: 25,
halo: true,
alignLabels: false,
showDebugInfos: false
},
...
};The labelSpace defines padding left and right in pixel or in percent of the total width (labelSpacePercent).
The lineHeightFactor defines the height. A lineHeightFactor of 1 means that each line is the same height as the font size.
The anchorCenterPercent defines the position of the inner point of the anchor line. 100 is exactly on the circle border while 0 is the center of the circle. 50 is therefore right in the middle of each pie arc.
Defines the font family and size.
The color of the text and the anchor lines.
Distance of the anchor line breaking point to the border of the circle.
Is true, when a white halo line should be drawn for better visual differentiation of the anchor lines.
The labels can all be aligned at the left/right edge of the diagram (alignLabels = true) or at the nearer distance to the circle, depending on the text length (alignLabels = false).
|:---:|:---:|
|
|
|
| alignLabels: false | alignLabels: true |
If this is set true there are additional infos like the line numbers are shown for debug purposes.










