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

164
Visualizações
Chart.js Scatter Chart bounds: 'data' Issue

I'm currently struggling with building a web frontend with a responsive chart, which should be filled with live data while the user is visiting the application.

My goal was to have the x-axis always scale automatically to perfectly cover the data. Then I found the bounds attribute of Chart.js, which when set to 'data' should do exactly what I want.

As you can see in this example, the whole thing only works well for the first few datasets - from x-values > 5 onwards, the scaling of the x-axis somehow gets messed up.

Did anyone else have this problem before? Did I assign other attributes incorrectly?

Here's my JavaScript code:

var data = [];

var graph = new Chart("chart", {
    type: 'scatter',
    data: {
        datasets: [{
            data: data,
            pointRadius: 0,
            borderWidth: 2,
            pointHitRadius: 4,
            pointHoverRadius: 6,
            tension: 0,
            showLine: true,
            xAxisID: "xAxis",
            yAxisID: "yAxis",
        }]
    },
    options: {
        responsive: true,
        maintainAspectRatio: false,
        animation: false,
        plugins: {
            legend: {
                display: false,
            },
        },
        interaction: {
            mode: 'nearest',
            intersect: true,
        },
        scales: {
            xAxis: {
                type: 'linear',
                position: 'bottom',
                title: {
                    display: true,
                    text: 't (s)',
                    color: "black",
                    font: {
                        size: 15
                    }
                },

            ticks: {
                color: "black",
                callback: (value, index, values) => (index == (values.length - 1)) ? "" : value,
            },
            bounds: 'data'
        },
        yAxis: {
            type: 'linear',
            position: 'left',
            ticks: {
                color: "black",
                maxTicksLimit: 7,
            }

        }
    }
}
});


var x = 0;
setInterval(function() {

var newData = {
    x: Math.round(x * 100) / 100,
    y: Math.round(x * 100) / 100
};

data.push(newData);

graph.update();

x += 0.1;

}, 100);
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