|
| 1 | +{{ target: component-total-label }} |
| 2 | + |
| 3 | +#${prefix} visible(boolean) = false |
| 4 | + |
| 5 | +Whether to display the total stack label, not displayed by default. |
| 6 | + |
| 7 | +Please note that the total stack label is only supported when the chart supports stack configuration (`stack: true`). |
| 8 | + |
| 9 | +#${prefix} interactive(boolean) = false |
| 10 | + |
| 11 | +Whether the data label graphic element supports interaction events, not supported by default. |
| 12 | + |
| 13 | +#${prefix} position('top' | 'bottom') = 'top' |
| 14 | + |
| 15 | +The position of the total label. Supported since version `1.13.7`. |
| 16 | + |
| 17 | +#${prefix} formatMethod(Function) |
| 18 | + |
| 19 | +The data label content formatting function, defined as follows: |
| 20 | + |
| 21 | +```ts |
| 22 | + /** |
| 23 | + * label format method |
| 24 | + * @param text origin text |
| 25 | + * @param datum graphic data |
| 26 | + * @returns formatted text |
| 27 | + */ |
| 28 | + formatMethod?: (text: string | string[], datum?: any) => string | string[] | number | number[] |
| 29 | +``` |
| 30 | + |
| 31 | +Since version `1.10.0`, `formatMethod` supports return richText structure like: |
| 32 | + |
| 33 | +```ts |
| 34 | +formatMethod: text => { |
| 35 | + return { |
| 36 | + type: 'rich', |
| 37 | + text: [ |
| 38 | + { |
| 39 | + text, |
| 40 | + fontSize: 14, |
| 41 | + fontWeight: 'bold', |
| 42 | + fill: 'red' |
| 43 | + }, |
| 44 | + { |
| 45 | + text: 'Rich Text', |
| 46 | + fontSize: 10, |
| 47 | + lineThrough: true, |
| 48 | + underline: true, |
| 49 | + fill: 'green' |
| 50 | + } |
| 51 | + ] |
| 52 | + }; |
| 53 | +}; |
| 54 | +``` |
| 55 | + |
| 56 | +For specific usage of rich text, please refer to the[Rich Text Tutorial Document](/vchart/guide/tutorial_docs/extend/Richtext_and_Dom) |
| 57 | + |
| 58 | +#${prefix} style(Object) |
| 59 | + |
| 60 | +Label graphic element style configuration. |
| 61 | + |
| 62 | +##${prefix} type='text'(Object) |
| 63 | + |
| 64 | +Regular text style configuration. |
| 65 | + |
| 66 | +{{ use: graphic-text( |
| 67 | + prefix = '##' + ${prefix} |
| 68 | +) }} |
| 69 | + |
| 70 | +##${prefix} type='rich'(Object) |
| 71 | + |
| 72 | +Rich text style configuration. |
| 73 | + |
| 74 | +{{ use: graphic-rich-text( |
| 75 | + prefix = '##' + ${prefix} |
| 76 | +) }} |
| 77 | + |
| 78 | +#${prefix} state(Object) |
| 79 | + |
| 80 | +Label state style configuration. |
| 81 | + |
| 82 | +##${prefix} hover(Object) |
| 83 | +Hover state style configuration. |
| 84 | + |
| 85 | +{{ use: graphic-text( |
| 86 | + prefix = '##' + ${prefix} |
| 87 | +) }} |
| 88 | + |
| 89 | +##${prefix} hover_reverse(Object) |
| 90 | + |
| 91 | +Non-hover state style configuration. |
| 92 | + |
| 93 | +{{ use: graphic-text( |
| 94 | + prefix = '##' + ${prefix} |
| 95 | +) }} |
| 96 | + |
| 97 | +##${prefix} selected(Object) |
| 98 | +Selected state style configuration. |
| 99 | + |
| 100 | +{{ use: graphic-text( |
| 101 | + prefix = '##' + ${prefix} |
| 102 | +) }} |
| 103 | + |
| 104 | +##${prefix} selected_reverse(Object) |
| 105 | +Non-selected state style configuration. |
| 106 | + |
| 107 | +{{ use: graphic-text( |
| 108 | + prefix = '##' + ${prefix} |
| 109 | +) }} |
| 110 | + |
| 111 | +#${prefix} overlap(Object|false) |
| 112 | + |
| 113 | +Label anti-overlap configuration. |
| 114 | + |
| 115 | +##${prefix} hideOnHit(boolean) = true |
| 116 | + |
| 117 | +Whether to hide the labels that cannot be placed due to overlapping detection. |
| 118 | + |
| 119 | +##${prefix} clampForce(boolean) = true |
| 120 | + |
| 121 | +Whether to constrain labels to be within the plotting area. |
| 122 | + |
| 123 | +##${prefix} avoidBaseMark(boolean) = false |
| 124 | + |
| 125 | +Whether to avoid the label corresponding to the base graphic element. In line charts / scatter plots / radar charts, the point element labels will be turned on by default, while in other charts, they are turned off by default. |
| 126 | + |
| 127 | +##${prefix} strategy(Array) |
| 128 | + |
| 129 | +Overlap avoidance strategy for labels, providing 4 avoidance strategies, respectively: |
| 130 | + |
| 131 | +- 'position': Optional position strategy. If the default position does not have enough space to place the label, consider the alternative positions within the position. |
| 132 | + |
| 133 | + ```ts |
| 134 | + export type PositionStrategy = { |
| 135 | + /** |
| 136 | + * Optional position strategy. |
| 137 | + * If the default position does not have enough space to place the label, consider the alternative positions within the position. |
| 138 | + */ |
| 139 | + type: 'position'; |
| 140 | + /** position supports different configurations depending on the chart type **/ |
| 141 | + position?: Functional<LabelPosition[]>; |
| 142 | + /** |
| 143 | + * When the alternative positions in position still cannot accommodate the label, whether the label is returned to its original position. |
| 144 | + * The default is true, if false, the label will be placed in the last position of the position array. |
| 145 | + * @since 1.12.15 |
| 146 | + * @default true |
| 147 | + */ |
| 148 | + restorePosition?: boolean; |
| 149 | + }; |
| 150 | + ``` |
| 151 | + |
| 152 | +- 'bound': Use when `label.position` is configured inside the graphic element (recommended for rect data element only). If the graphic size is not enough to accommodate the label, consider the alternative positions within the position. |
| 153 | + |
| 154 | + ```ts |
| 155 | + export type BoundStrategy = { |
| 156 | + /** |
| 157 | + * Used when configuring labels inside a graphic. |
| 158 | + * If the graphic size is insufficient to accommodate the label, consider alternative positions within the position. |
| 159 | + */ |
| 160 | + type: 'bound'; |
| 161 | + /** position supports different configurations depending on the chart type **/ |
| 162 | + position?: Functional<LabelPosition[]>; |
| 163 | + /** |
| 164 | + * When the alternative positions in position still cannot accommodate the label, whether the label is returned to its original position. |
| 165 | + * The default is true, if false, the label will be placed in the last position of the position array. |
| 166 | + * @since 1.12.15 |
| 167 | + * @default true |
| 168 | + */ |
| 169 | + restorePosition?: boolean; |
| 170 | + }; |
| 171 | + ``` |
| 172 | + |
| 173 | +- `moveY`: Y-direction scatter strategy. If the default position does not have enough space to place the label, find the position in the Y-direction based on the offset. |
| 174 | + |
| 175 | + ```ts |
| 176 | + export type MoveYStrategy = { |
| 177 | + /** |
| 178 | + * Y-direction dispersion strategy. |
| 179 | + * If the default position does not have enough space to place the label, find a position in the y-direction based on the offset. |
| 180 | + */ |
| 181 | + type: 'moveY'; |
| 182 | + /** |
| 183 | + * The position offset in the y-direction can be configured as a function. |
| 184 | + */ |
| 185 | + offset: Functional<number[]>; // number | (data: any) => number[]; |
| 186 | + }; |
| 187 | + ``` |
| 188 | + |
| 189 | + - `moveX`: X-direction scatter strategy. If the default position does not have enough space to place the label, find the position in the X-direction based on the offset. |
| 190 | + |
| 191 | + ```ts |
| 192 | + export type MoveYStrategy = { |
| 193 | + /** |
| 194 | + * X-direction dispersion strategy. |
| 195 | + * If the default position does not have enough space to place the label, find a position in the x-direction based on the offset. |
| 196 | + */ |
| 197 | + type: 'moveX'; |
| 198 | + /** |
| 199 | + * The position offset in the x-direction can be configured as a function. |
| 200 | + */ |
| 201 | + offset: Functional<number[]>; // number | (data: any) => number[]; |
| 202 | + }; |
| 203 | + ``` |
| 204 | + |
| 205 | +##${prefix} padding(Object) |
| 206 | + |
| 207 | +防重叠区域的扩展边距,自 `1.13.7` 版本支持。默认值为`{ top: 0, bottom: 0, left: 0, right: 0}`。 |
| 208 | + |
| 209 | +默认情况下,图表标签被要求布局在 region 区域内部,若希望标签超出 region 区域布局并依然正确计算防重叠,可以配置 `padding`。 |
0 commit comments