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

149
Visualizações
real time scrolling based chart with chart.js

i want to create real time graph with scrolling time such as in the following video:https://www.youtube.com/watch?v=2-tnkzG0sKU

is this possible with chart.js? I have so far the following, it is scrolling but the time is not showing up, i want to show in seconds.

let dataSize = 500;
let readings = new Array(dataSize);    
// data object for the chart:
const data = {
  // X axis labels
  labels: new Array(),
  datasets: [{
    data: readings,         // the data to chart
    borderColor: '#272323', // line color (lavender)
    pointRadius: 0.5          // point size
  }]
};

const config = {
  type: 'line',         // type of chart
  data: data,           // the data
  options: {
    animation: false,   // remove animation to speed drawing up
    responsive: true,
    maintainAspectRatio: false,
    scales: {           // axis ranges:
      y: {
        type: 'linear',
        min: 0,
        max: 255
      },
      x:{
      //  ticks:{
          type: 'time',
          time:{
            //unit:'second',
            displayFormats: {hour: 'mm:ss'}
          },
          min:0,
          max: dataSize,
          //beginAtZero: true,
          maxTicksLimit: dataSize/2
        //}
      }
    }
  }
};

thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Easyest way to achieve this is by using the streaming plugin for chart.js: https://nagix.github.io/chartjs-plugin-streaming/master/guide/#table-of-contents

You will get something like this where in your onRefresh you add your data.

npm i chartjs-plugin-streaming

import ChartStreaming from 'chartjs-plugin-streaming';
import 'anyDatAdapterFromAhichDateLibYouAreUsing';

Chart.register(ChartStreaming);

const myChart = new Chart(ctx, {
  options: {
    scales: {
      x: {
        type: 'realtime',
        realtime: {
          onRefresh: function(chart) {
            chart.data.datasets.forEach(function(dataset) {
              dataset.data.push({
                x: Date.now(),
                y: Math.random()
              });
            });
          }
        }
      }
    }
  }
});
about 4 years ago · Juan Pablo Isaza Relatório
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