You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add style option to legend labels config suppoting box, line and point style
- Deprecate usePointStyle option
- BoxWidth is now calculated for each legend item as it can have different width
- Fix the existing tests and add more tests
- Update document
Copy file name to clipboardExpand all lines: docs/configuration/legend.md
+35-19Lines changed: 35 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ The legend configuration is passed into the `options.legend` namespace. The glob
7
7
8
8
| Name | Type | Default | Description
9
9
| -----| ---- | --------| -----------
10
-
| `display` | `Boolean` | `true` | is the legend shown
10
+
| `display` | `Boolean` | `true` | Whether the legend is shown
11
11
| `position` | `String` | `'top'` | Position of the legend. [more...](#position)
12
12
| `fullWidth` | `Boolean` | `true` | Marks that this box should take the full width of the canvas (pushing down other boxes). This is unlikely to need to be changed in day-to-day use.
13
13
| `onClick` | `Function` | | A callback that is called when a click event is registered on a label item
@@ -28,15 +28,28 @@ The legend label configuration is nested below the legend configuration using th
| `fontSize` | `Number` | `12` | Font size of text
33
+
| `fontStyle` | `String` | `'normal'` | Font style of text
34
34
| `fontColor` | `Color` | `'#666'` | Color of text
35
35
| `fontFamily` | `String` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Font family of legend text.
36
36
| `padding` | `Number` | `10` | Padding between rows of colored boxes.
37
37
| `generateLabels` | `Function` | | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See [Legend Item](#legend-item-interface) for details.
38
38
| `filter` | `Function` | `null` | Filters legend items out of the legend. Receives 2 parameters, a [Legend Item](#legend-item-interface) and the chart data.
39
-
| `usePointStyle` | `Boolean` | `false` | Label style will match corresponding point style (size is based on fontSize, boxWidth is not used in this case).
39
+
| `style` | `String` | | Style of the label item. [more...](#label-style)
40
+
41
+
### Label Style
42
+
43
+
Possible label style values are:
44
+
*`'box'`
45
+
*`'line'`
46
+
*`'point'`
47
+
48
+
`'box'` will draw a box using the background color, border width and color of the corresponding element.
49
+
`'line'` will draw a line using the corresponding line style.
50
+
`'point'` will make the label style match the corresponding point style (size is based on `fontSize`, `boxWidth` is not used in this case).
51
+
52
+
If not set, the `'line'` style is used for line elements, and the `'box'` style for other elements.
40
53
41
54
## Legend Item Interface
42
55
@@ -53,26 +66,29 @@ Items passed to the legend `onClick` function are the ones returned from `labels
53
66
// If true, this item represents a hidden dataset. Label will be rendered with a strike-through effect
54
67
hidden:Boolean,
55
68
56
-
// For box border. See https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D/lineCap
69
+
// For line border. See https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D/lineCap
57
70
lineCap:String,
58
71
59
-
// For box border. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
72
+
// For line border. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
60
73
lineDash:Array[Number],
61
74
62
-
// For box border. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
75
+
// For line border. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
63
76
lineDashOffset:Number,
64
77
65
-
// For box border. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
78
+
// For line border. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
66
79
lineJoin:String,
67
80
68
-
// Width of box border
81
+
// Width of box border or line
69
82
lineWidth:Number,
70
83
71
-
// Stroke style of the legend box
72
-
strokeStyle: Color
84
+
// Stroke style of the legend box or line
85
+
strokeStyle: Color,
73
86
74
-
// Point style of the legend box (only used if usePointStyle is true)
75
-
pointStyle:String
87
+
// Point style of the legend box (only used if style is 'point')
0 commit comments