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

428
Visualizações
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 Respostas
Responde à pergunta

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 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