Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

437
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!