Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

chart js 3 radar, how to enabe multiline labels

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 .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

enter image description here

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading