# Label Annotations
Label annotations are used to add contents on the chart area. This can be useful for describing values that are of interest.
# Configuration
The following options are available for label annotations.
Name | Type | Scriptable | Default |
---|---|---|---|
adjustScaleRange | boolean | Yes | true |
backgroundColor | Color | Yes | transparent |
borderCapStyle | string | Yes | 'butt' |
borderColor | Color | Yes | options.color |
borderDash | number[] | Yes | [] |
borderDashOffset | number | Yes | 0 |
borderJoinStyle | string | Yes | 'miter' |
borderRadius | number | object | Yes | 0 |
borderWidth | number | Yes | 0 |
callout | object | Yes | |
color | Color | Yes | 'black' |
content | string |string[] |Image (opens new window)|HTMLCanvasElement (opens new window) | Yes | null |
display | boolean | Yes | true |
drawTime | string | Yes | 'afterDatasetsDraw' |
font | Font | Yes | {} |
height | number |string | Yes | undefined |
padding | Padding | Yes | 6 |
position | string |{x: string, y: string} | Yes | 'center' |
textAlign | string | Yes | 'center' |
width | number |string | Yes | undefined |
xAdjust | number | Yes | 0 |
xMax | number | string | Yes | undefined |
xMin | number | string | Yes | undefined |
xScaleID | string | Yes | 'x' |
xValue | number | string | Yes | undefined |
yAdjust | number | Yes | 0 |
yMax | number | string | Yes | undefined |
yMin | number | string | Yes | undefined |
yScaleID | string | Yes | 'y' |
yValue | number | string | Yes | undefined |
# General
If one of the axes does not match an axis in the chart, the content will be rendered in the center of the chart. The 2 coordinates, xValue, yValue are optional. If not specified, the content will be rendered in the center of the chart.
The 4 coordinates, xMin, xMax, yMin, yMax are optional. If not specified, the box is expanded out to the edges in the respective direction and the box size is used to calculated the center of the point. To enable to use the box positioning, the radius
must be set to 0
or NaN
.
Name | Description |
---|---|
adjustScaleRange | Should the scale range be adjusted if this annotation is out of range |
content | The content to show in the text annotation. |
display | Whether or not this annotation is visible |
drawTime | See drawTime. |
height | Overrides the height of the image or canvas element. Could be set in pixel by a number, or in percentage of current height of image or canvas element by a string. If undefined, uses the height of the image or canvas element. It is used only when the content is an image or canvas element. |
padding | The padding to add around the text label. |
textAlign | Text alignment of label content when there's more than one line. Possible options are: 'left' , 'start' , 'center' , 'end' , 'right' . |
width | Overrides the width of the image or canvas element. Could be set in pixel by a number, or in percentage of current width of image or canvas element by a string. If undefined, uses the width of the image or canvas element. It is used only when the content is an image or canvas element. |
xAdjust | Adjustment along x-axis (left-right) of label relative to computed position. Negative values move the label left, positive right. |
xMax | Right edge of the box in units along the x axis. |
xMin | Left edge of the box in units along the x axis. |
xScaleID | ID of the X scale to bind onto, default is 'x'. |
xValue | X coordinate of the point in units along the x axis. |
yAdjust | Adjustment along y-axis (top-bottom) of label relative to computed position. Negative values move the label up, positive down. |
yMax | Bottom edge of the box in units along the y axis. |
yMin | Top edge of the box in units along the y axis. |
yScaleID | ID of the Y scale to bind onto, default is 'y'. |
yValue | Y coordinate of the point in units along the y axis. |
# Styling
Name | Description |
---|---|
backgroundColor | Fill color. |
borderCapStyle | Cap style of the border line. See MDN (opens new window). |
borderColor | Stroke color. |
borderDash | Length and spacing of dashes. See MDN (opens new window). |
borderDashOffset | Offset for border line dashes. See MDN (opens new window). |
borderJoinStyle | Border line joint style. See MDN (opens new window). |
borderWidth | Stroke width (in pixels). |
color | Text color. |
font | Text font. |
# Position
A position can be set in 2 different values types:
'start'
,'center'
,'end'
which are defining where the label will be located- a
string
, in percentage format'number%'
, is representing the percentage on the size where the label will be located
If this value is a string (possible options are 'start'
, 'center'
, 'end'
or a string in percentage format), it is applied to vertical and horizontal position in the box.
If this value is an object, the x
property defines the horizontal alignment in the label, with respect to the selected point. Similarly, the y
property defines the vertical alignment in the label, with respect to the selected point. Possible options for both properties are 'start'
, 'center'
, 'end'
, a string in percentage format. Omitted property have value of the default, 'center'
.
# borderRadius
If this value is a number, it is applied to all corners of the rectangle (topLeft, topRight, bottomLeft, bottomRight). If this value is an object, the topLeft
property defines the top-left corners border radius. Similarly, the topRight
, bottomLeft
, and bottomRight
properties can also be specified. Omitted corners have radius of 0.
# Callout
A callout connects the label by a line to the selected point.
Namespace: options.annotations[annotationID].label.callout
, it defines options for the callout on the annotation label.
const options = { plugins: { autocolors: false, annotation: { annotations: { label1: { type: 'label', xValue: 2.5, yValue: 60, xAdjust: 290, yAdjust: -100, backgroundColor: 'rgba(245,245,245)', content: ['In this point of time,', 'something happened'], textAlign: 'start', font: { size: 18 }, callout: { enabled: true, side: 10 } } } } } };
All of these options can be Scriptable.
Name | Type | Default | Notes |
---|---|---|---|
borderCapStyle | string | 'butt' | Cap style of the border line of callout. See MDN (opens new window). |
borderColor | Color | undefined | Stroke color of the pointer of the callout. |
borderDash | number[] | [] | Length and spacing of dashes of callout. See MDN (opens new window). |
borderDashOffset | number | 0 | Offset for line dashes of callout. See MDN (opens new window). |
borderJoinStyle | string | 'miter' | Border line joint style of the callout. See MDN (opens new window). |
borderWidth | number | 1 | Stroke width of the pointer of the callout. |
enabled | boolean | false | If true, the callout is drawn. |
margin | number | 5 | Amount of pixels between the label and the callout separator. |
position | string | 'auto' | The position of callout, with respect to the label. Could be left , top , right , bottom or auto . |
side | number | 5 | Width of the starter line of callout pointer. |
start | number |string | '50%' | The percentage of the separator dimension to use as starting point for callout pointer. Could be set in pixel by a number, or in percentage of the separator dimension by a string. |