2👍
✅
Assuming, you want to place the legend
right of your chart, you need to define the option plugins.legend.position: 'right'
.
Further information is available at Chart.js documentation here.
Please take a look at below runnable snippet and see how it works.
new Chart('myChart', {
type: 'bar',
data: {
labels: ['A', 'B', 'C', 'D'],
datasets: [{
label: 'Dataset',
data: [4, 2, 5, 3],
}]
},
options: {
plugins: {
legend: {
display: true,
position: 'right'
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.2/chart.min.js"></script>
<canvas id="myChart"></canvas>
Source:stackexchange.com