mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Enable multi-line axis titles (#8579)
This commit is contained in:
parent
a23f1de6df
commit
279b6ae1da
@ -12,7 +12,7 @@ Namespace: `options.scales[scaleId].title`, it defines options for the scale tit
|
||||
| ---- | ---- | ------- | -----------
|
||||
| `display` | `boolean` | `false` | If true, display the axis title.
|
||||
| `align` | `string` | `'center'` | Alignment of the axis title. Possible options are `'start'`, `'center'` and `'end'`
|
||||
| `text` | `string` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
|
||||
| `text` | `string`\|`string[]` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
|
||||
| `color` | [`Color`](../general/colors.md) | `Chart.defaults.color` | Color of label.
|
||||
| `font` | `Font` | `Chart.defaults.font` | See [Fonts](../general/fonts.md)
|
||||
| `padding` | `number`\|`object` | `4` | Padding to apply around scale labels. Only `top` and `bottom` are implemented.
|
||||
|
||||
@ -177,8 +177,9 @@ function getTitleHeight(options, fallback) {
|
||||
|
||||
const font = toFont(options.font, fallback);
|
||||
const padding = toPadding(options.padding);
|
||||
const lines = isArray(options.text) ? options.text.length : 1;
|
||||
|
||||
return font.lineHeight + padding.height;
|
||||
return (lines * font.lineHeight) + padding.height;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
32
test/fixtures/core.scale/title-multi-line.js
vendored
Normal file
32
test/fixtures/core.scale/title-multi-line.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
module.exports = {
|
||||
config: {
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: [1, -1, 3],
|
||||
}],
|
||||
labels: ['Label1', 'Label2', 'Label3']
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
title: {
|
||||
display: true,
|
||||
text: [
|
||||
'Line 1',
|
||||
'Line 2',
|
||||
'Line 3',
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
options: {
|
||||
spriteText: true,
|
||||
canvas: {
|
||||
height: 256,
|
||||
width: 512
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/core.scale/title-multi-line.png
vendored
Normal file
BIN
test/fixtures/core.scale/title-multi-line.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
2
types/index.esm.d.ts
vendored
2
types/index.esm.d.ts
vendored
@ -2698,7 +2698,7 @@ export interface CartesianScaleOptions extends CoreScaleOptions {
|
||||
|
||||
title: {
|
||||
display: boolean;
|
||||
text: string;
|
||||
text: string | string[];
|
||||
color: Color;
|
||||
font: FontSpec;
|
||||
padding: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user