Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
Chart JS annotation issues

I am trying to load annotation the dynamic chart that I create after receiving data from the database and I have tried all possible options but somehow the chart loads but no the annotations.

chart.js version = v2.9.4 chart-plugin-annotation.min.js version = 0.5.7

Function in JS that runs when data is receiving from db:

function DrawChart(timeLabelList, unitsProducedList, goalList){
    if(draw_the_chart != null) draw_the_chart.destroy();

    Chart.defaults.global.defaultFontColor = 'white';
    var ctx = document.getElementById('draw_the_chart').getContext("2d");

    draw_the_chart = new Chart(ctx, {
        type: 'line',
        //plugins: [ChartAnnotation],
        data: {
            labels: timeLabelList,
            datasets: [
                {
                    label: 'Goal',
                    yAxisID: 'A',
                    data: goalList,
                    //backgroundColor: chartColumnColorBlueSolid,
                    borderColor: chartColumnColorGreenSolid,
                    borderWidth: 2,
                    pointStyle: 'star'
                }]
        },
        options: {
            annotation: {
                annotations: [
                  {
                    id: "a-line-1",
                    type: "line",
                    mode: "vertical",
                    scaleID: "y-axis-0",
                    value: "1",
                    borderColor: "red",
                    borderWidth: 2
                  }
                ]
            },
            legend: {
                position: 'bottom',
                display: true,
            },
            elements: {
                line: {
                    tension: 0
                }
            },
            scales: {
                xAxes: [{
                    stacked: true,
                    type: 'time',
                    time: {
                        unit: 'hour'
                    },
                }],
                yAxes: [{
                    stacked: false,
                    id: 'A',
                    type: 'linear',
                    position: 'right',
                }]
            },
        }
    });
}

I tried all possible ways to register and also different ways to used the plugin but had no luck plotting it. I even used latest CDN versions but had no luck.

Can anyone help with it.

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda