chartjs / chartjs/Chart.js

Legend not displaying all labels

Open
#10,893 4 comments 1 reaction 0 assignees View on GitHub
status: implement externally type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

I am creating a stacked, horizontal bar chart with 6 datasets. The label of each dataset should appear in the legend

### Current behavior

Only the first 4 labels are being displayed in the legend. Seems like canvas height is not long enough to fit the content
![Untitled](https://user-images.githubusercontent.com/47416784/202872845-4f1eed1e-af11-4744-856e-bac1eb4501ed.png)

### Reproducible sample

https://codepen.io/kosn1/pen/abKENbp

### Optional extra steps/info to reproduce

Here is my html code

```




```
and the js
```
const projectsLineChart = new Chart(
document.getElementById('line-chart'), {
type: 'bar',
data: {
labels: [''],
datasets: [

{
label: Dataset 1',
barThickness: 12,
data: [312],

}, {
label: 'Dataset 2',
barThickness: 12,
data: [238],
},
{
label: 'Dataset 3',
barThickness: 12,
data: [538],

},
{
label: 'Dataset 4',
barThickness: 12,
data: [58],

},
{
label: 'Dataset 5',
barThickness: 12,
data: [158],

},
]
},
options: {
plugins: {
legend: {
position: 'bottom',
title: {
display: true,
text: 'Datasets',
padding: {
top: 15
},
font: {
size: 18
}
}

}
},
indexAxis: 'y',
responsive: true,
scales: {
x: {

stacked: true,
},
y: {

stacked: true,

}
},
},

}
);
```

### Possible solution

Is there a way so the canvas height always adjust to its contents dynamically?

### Context

_No response_

### chart.js version

4.0.1

### Browser name and version

Google Chrome 107.0.5304.107

### Link to your project

_No response_

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.