Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
chartJS - Line Chart - DataLabels Formatting Function not working

I have the following HTML/JS code as follows which takes two lists:

  • labels
  • values

And converts it into a line chart with labels on the points:

<div style = "position:relative; bottom:140px; z-index: -2;">
<canvas id="lineChart" width = 600 height = 200></canvas>
<script>
    Chart.register(ChartDataLabels);
    var ctx = document.getElementById("lineChart").getContext("2d");
    var linechart = new Chart(ctx, {
        type: "line",
        data: {
            labels: {{ labels | safe}},
            datasets: [
                {
                    label: "Data points",
                    data: {{ values | safe}},
                    fill: false,
                    borderColor: "rgb(75, 192, 192)",
                    lineTension: 0.5
                }
            ]
        },
        options: {
        responsive: true,
        layout: {
            padding: {
                top: 100
                    }
                },
        scales: {
          x: {
            grid: {
              display: false
            }
          },
          y: {
            display: false,
          }
        },

        plugins: {
            legend: {
                display: false
            },
            datalabels: {
                anchor: 'end',
                align: 'top',
                formatter: Math.round,
                font: {
                    weight: 'bold',
                    size: 15
                }
            }

        }
        }
    });
</script>

This is working fine:

enter image description here

However, I want the labels to have the '£' symbol before and 'm' after

Every time I try to use the formatter function like:

formatter: function(value){
            return value + 'm';

Or any other combination, the chart fails to return. I am completely perplexed why.

Any suggestions?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda