Currently, I am working on creating a custom legend for my donut chart using the ChartJS library. While I have successfully created the donut chart with the default legend provided by ChartJS, I now require some modifications.
Specifically, I would like to display the value above the car name and remove the sticky legend so that I can customize the style for fonts and boxes (such as next to the text "Audi").
I am aware of the Legend generator tool, but I am unsure how to integrate it with VueJS since I am using VueJS as a framework.
You can view the current appearance of my legend here - https://i.sstatic.net/J2GEf.jpg
Below is a snippet of my code:
Within a Vue component where I import a donut component:
<div class="col-md-6">
<div class="chart-box">
<p class="chart-title">Cars</p>
<donut-message id="chart-parent"></donut-message>
</div>
</div>
Javascript:
import { Doughnut } from 'vue-chartjs'
export default Doughnut.extend({
ready () {
Chart.defaults.global.tooltips.enabled = false;
Chart.defaults.global.legend.display = false;
this.render({
labels: ['Audi','BMW','Ford','Opel'],
datasets: [
{
label: 'Cars',
backgroundColor: ['#35d89b','#4676ea','#fba545','#e6ebfd'],
data: [40, 30, 20, 10]
}
]
},
{
responsive: true,
cutoutPercentage: 75,
legend: {
display: true,
position: "right",
fullWidth: true,
labels: {
boxWidth: 10,
fontSize: 14
}
},
animation: {
animateScale: true
}
})
}
});