I’m using chart js 3 to draw a radar graph .
I’m getting labels text from backend .
I’m trying to make labels responsive and apply multilines and wrap words .
My current config is :
const myChart = new Chart(ctx, {
type: "radar",
data: {
labels: labels,
datasets: [
...
I added a liste of options to make graph responsive and to give a custom style :
options: {
scales: {
r: {
pointLabels: {
font: {
fontSize: 14,
fontFamily: "Roboto",
},
},
},
},
maintainAspectRatio: false,
responsive: true,
layout: {
padding: 0,
},
tooltips: {
enabled: false,
},
plugins: {
title: {
display: false,
text: "Les évaluations",
},
legend: {
display: false,
},
},
},
I’m getting this graph :
I can’t find and options to enable multlines labels or to apply wrap to text
>Solution :
Actually, your variable labels is an array containing strings in this way: ["Je note la qualité du pitch...", "Je donne ma voix pour sélectionner cette startup, sous réserve"]
What you have to do is to make a 2D Array containing your same sentences but splitted in sub array like that : [["Je note la qualité", "du pitch..."], ["Je donne ma voix", "pour sélectionner", "cette startup, sous réserve"]]
By doing this, you should have multi lines sentences, to break your string into multiple strings (chunks), here is a quick implementation :
const newLabels = labels.map(l => l.match(/.{1,n}/g)) where n is your max length per line.
