chartjs / chartjs/Chart.js

Legend title does not fit

Open
#11,850 2 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

First of all Documentation is still very annoying.
You just need to put a complete HTML file in there so people can have all the parts together. Anyone with basic knowledge of HTML,CSS,Javascript should be able to understand it. With the way that you have arranged your documentation, first you need top open 5 different pages to setup a working sample, then go to example pages and try to figure out which one of those chunks of codes goes where! This has been pointed out so many times.
Also in getting started only specifies use of CDN, but when even using cdn with version umd version should be used and not just chart.min.js version like any other library. `cdnjs.com` also does not have all the versions that are available in `jsdelivr.com`

### ISSUE ITSELF

This issue not only applies to latest version of the Chart.JS (4.3.3 at the moment) but all the versions above 3.
Previously it was possible to get around this issue using [`generateLegend()`](https://stackoverflow.com/a/43230400) function which was removed. The replacement method [HTML Legend](https://www.chartjs.org/docs/master/samples/legend/html.html) is to complicated and since the example is split in chunks with some missing and due to use of framework in examples, `view source` in browser wont work help to find what's going on either.

Following is a simple page that will show the problem (in screenshot too), I have tested this against all the versions from 4.2.1 up to 4.3.3

```html


const config = {
type: 'doughnut',
data: {
labels: ['ABC', 'DEF'],
datasets: [{ data: [50.00, 10.00,] },]
},
options: {
plugins: {
legend: {
title: {
text: function () { return '4ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'; },
display: true,
},
position: 'left'
}
}
},
};

let pie_chart = new Chart(document.getElementById("pieChart"), config);

```

As you can see in following screenshot, the legend title is trimmed from both side. I could not find a property or method to fix this issue.

![image](https://github.com/user-attachments/assets/05411aa2-4009-467a-96a6-5004d5dcccc8)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.