Issue with data decimation in Chart.js, encountering problems with parsing

I'm facing a challenge while plotting a graph using chart JS with approximately 300,000 data points. The performance is slow, so I am exploring ways to enhance it by utilizing the data decimation plugin. However, the data doesn't seem to be getting decimated as expected.

Here's a snippet 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"
    }
]

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

I believe requirements 1, 2, and 3 are met. However, enabling parsing: false in the config causes issues with my plot.

What could be wrong with my data structure that prevents chart js from interpreting it accurately?

Any advice or assistance on this matter would be greatly appreciated. Thank you.

Update

Below is the function I used to generate 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;
};

Answer №1

Explore the information on data interpretation in the following documentation: https://www.chartjs.org/docs/latest/api/interfaces/ParsingOptions.html#parsing

Learn how to interpret the dataset. Disabling data interpretation can be done by specifying parsing: false in the chart options or dataset. When parsing is turned off, data must be organized and formatted in a way that matches the requirements of the chart type and scales being used.

Resolution: Ensure that your x-axis data (timetags) is in "milliseconds since epoch" format, which is the internal time representation used by chartjs. Currently, your x-axis data is in date string format, which is why it's not functioning correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a DiscordAPIError[10062] when attempting to retrieve user points from the database due to an unknown interaction

content: "Congratulations, you have been successfully verified!", ephemeral: true, }); } } else if (interaction.customId === "giverole") { const userPoints = await findUser(interaction.member ...

sort the array based on its data type

Recently diving into typescript... I have an array that is a union of typeA[] | typeB[] but I am looking to filter based on the object's type interface TypeA { attribute1: string attribute2: string } interface TypeB { attribute3: string attri ...

VueJS - Iterating over a list within a vue component causes the list to be empty

Having encountered an issue with the answers provided to my question from yesterday, I have decided to create a new query with additional details. To review the original question, please visit: VueJS - using mustache template strings inside href attribute ...

The function `req.on('end', callback)` in Node.js is not functioning as expected

I am currently working on building a proxy using nodejs. The syntax I am using for sending and receiving https requests and responses works well, but in my project, I have noticed that the response is sometimes larger than expected. This results in req.on( ...

Rendering React Router server-side with client-side session information

Currently, I am working with mozilla client-sessions in conjunction with express/node. My goal is to pass my session.user to the react-router within a standard * request. Despite my efforts and attempts, I keep encountering an issue where it becomes unde ...

Assessing the string to define the structure of the object

Currently, I am attempting to convert a list of strings into a literal object in Javascript. I initially tried using eval, but unfortunately it did not work for me - or perhaps I implemented it incorrectly. Here is my example list: var listOfTempData = [ ...

Tips for choosing a dynamically generated ajax element

Question for you: I have a snippet of HTML code that looks like this: <li class='entry'> <div class='entryContent'> <p class='entryText'>Entry text></p> <a href="#" c ...

Exploring the differences between server-side rendering and client-side rendering in Express using Pug

I find myself in a state of confusion when it comes to distinguishing between what is considered client-side and server-side. Currently, as I develop a website using Pug for my HTML pages without any external files being loaded into the client's brows ...

Using Selenium in JavaScript to upload an image is a straightforward process

I am trying to automate the process of uploading a picture using Selenium with the following script: driver.findElement(By.id(`avatar-upload`)).sendKeys(`/home/user/Desktop/smg935-0hero-0930.jpeg`) But I keep receiving this error: ElementNotInteractable ...

Is there a way to easily copy the content within the <code> tag to the clipboard?

I've attempted to use the following code, but unfortunately, it's not functioning properly. Is there a way for me to copy the contents inside the <code> tag to my clipboard? <pre id="myCode"> <code> console.lo ...

Guide to incorporating navigation buttons (back and forward) in a modal box

I have successfully created image thumbnails and linked them using the provided code. <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script> <script src="https://maxcdn.bootstra ...

Issue encountered while subscribing to SalesForce topic using Node.js

Attempting to subscribe to a SalesForce topic through a Node.js server using the code provided in the JSForce documentation: conn.streaming.topic("InvoiceStatementUpdates").subscribe(function(message) { console.log('Event Type : ' + message.ev ...

The most efficient method for creating a substantial amount of pre-existing HTML within the DOM using jQuery

This particular webpage layout showcases articles contributed by users. Our platform allows users to publish their articles, which are added to the top of the page instantly while also being saved to the database via AJAX. <div class = 'article-wr ...

Having trouble loading a CSV file into a static folder using Node.js and Express

As a newcomer to node and express, I am exploring the integration of d3 visualizations into my web page. Essentially, I have a JavaScript file that creates all the d3 elements, which I then include in my .ejs file. I am currently attempting to replicate a ...

Is there a different option to use instead of the onChange event for the <select> element in ReactJS?

As I work on developing a Component with numerous <select> elements, the challenge arises when only one option is available and onChange event fails to trigger. Is there an alternative event in ReactJS, such as onSelect, that can be employed for this ...

Tips for troubleshooting my website?

After making some updates to my website, I noticed that an ajax script is no longer functioning properly. Since I hired someone else to write the code, I'm not sure how to troubleshoot it. Initially, this is what it should look like: When you select ...

What is the best way to retrieve the height of a <DIV> element without factoring in the presence of a horizontal scrollbar with

I have created a unique jQuery plugin that involves utilizing two nested <DIV> elements. The outer div is set with a fixed width and overflow: scroll, while the inner div (which is wider) houses the content for scrolling purposes. Everything is fun ...

What causes Json to be invalid on iOS?

When validating JSON, I encountered an issue with the "body" property. I have printed out the properties for "body", which you can view in the screenshot https://i.sstatic.net/Ifg5R.png ...

How to trigger a function when clicking on a TableRow in React using MaterialUI

Can someone help me understand how to add an onClick listener to my TableRow in React? I noticed that simply giving an onClick prop like this seemed to work: <TableRow onClick = {()=> console.log("clicked")}> <TableCell> Content </Ta ...

The issue of Ajax failing to execute an HTTP POST request in an HTML environment

I am creating a sample HTML code that involves making HTTP post requests using an Ajax function. The task at hand is to execute 2 HTTP POST requests and 1 GET request sequentially based on the correct response received. POST: URL: http://localhost:8082 ...