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

430
Vistas
Chart js data decimation not working, parsing issue

I am trying to plot a graph using chart JS that has around 300,000 data points. It runs pretty slowly so I'm trying to improve its performance by using the data decimation plugin. However, the data isn't being decimated at all.

Sample of my code:

const dataset = {
    datasets: {[,
        data : [{
        x  : timetag,
        y  : data,
      }],
      id   : 'id',
      label: 'label',
      indexAxis: 'x'
      ,]}

const config = {
  type: 'line',
  data:  dataset,
  options: {
  //  parsing: false,
    animation: false,
    scales : {
      x: {
        type: 'time',
        title: {
          display: true,
          text: 'Time Of Day'},
          },
      y:{
        min : 0,
},
        }}};

const myChart = new Chart(
  document.getElementById("Chart"),
  config
);

function decimateData(myChart) { 
  myChart.options.plugins.decimation.algorithm = 'lttb';
  myChart.options.plugins.decimation.enabled = true;
  myChart.options.plugins.decimation.samples = 50;
  myChart.update()

}

sample of the data structure
[
    {
        "x": "2022-02-24 00:00:26",
        "y": "11"
    },
    {
        "x": "2022-02-24 00:00:27",
        "y": "7"
    },
    {
        "x": "2022-02-24 00:00:28",
        "y": "8"
    }
]

From the chart js docs:

  1. The dataset must have an indexAxis of 'x'
  2. The dataset must be a line
  3. The X axis for the dataset must be either a 'linear' or 'time' type axis
  4. Data must not need parsing, i.e. parsing must be false
  5. The dataset object must be mutable. The plugin stores the original data as dataset._data and then defines a new data property on the dataset.

1,2,3 are fulfilled I believe. 4, turning on parsing: false in the config stops my plot from working altogether.

What is incorrect about my data structure that wont allow chart js to read it.

Any guidance is much appreciated thanks

Update

Here is the function I used to create the data options in the config block:

function genDatasets() {
  base = {
    datasets: [],
    parsing: false,,
    fill: false};
  for (var i = 0; i < sources.length; i++){

    set =[{
      data : [{
        x  : timetags,
        y  : data,
      }],
      id   : sources[i].slice(0,-4),
      label: sources[i].slice(0,-4),
      borderColor: colours[i],
      indexAxis: 'x'
      ,}]
    base['datasets'].push(set[0]) ;
  }
  return base;
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Look at the documentation about parsing: https://www.chartjs.org/docs/latest/api/interfaces/ParsingOptions.html#parsing

How to parse the dataset. The parsing can be disabled by specifying parsing: false at chart options or dataset. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.

Solution: your x-axis data (timetags) need to be "milli-second from epoch", which is the internal representation chartjs use for time value. Currently your x-axis data is a date string, that's why it's not working

about 4 years ago · Juan Pablo Isaza Denunciar
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