Error in the data format or configuration within the chart.js streaming data plugin

I'm in the process of setting up a live streaming data chart that reads data from a page displaying the most recent data points every second. I am utilizing the chart.js-plugin-streaming plugin developed by nagix for this task.

The challenge I'm facing is that the data resolution varies based on the sensor connected to the backend. Some sensors produce 1 data point per second while others generate 10 data points per second. Refreshing the chart at a high frequency could strain processing power and overload sensor requests, especially on older computers.

To address this issue, I designed a system where the URL outputs an array containing the last 20 data points (equivalent to approximately 2 to 20 seconds of data) and refreshes the chart once per second.

However, instead of only appending new data points to the existing chart, I encountered unexpected behavior. Upon checking the timestamps, they appear to be accurate.

The data array is fetched using a simple jQuery $.get() call to a Django view URL responsible for generating the data array each time it's called.

Here's an example of the URL output structure for a sensor producing 1 data point per second:

[
{y: 0.74, x: 1558531380957},
{y: 0.96, x: 1558531379950},
{y: 1.08, x: 1558531378942},
...
]

Upon subsequent calls, the first data point is removed, and a new data point is added to the end of the array, creating a scrolling effect.

The objects within the array are formatted as follows:

{"y": <float>, "x": <timestamp-in-ms>}

My current chart configuration:

$(document).ready(function() {
    // Chart settings 
});

While the chart functions correctly overall, the issue arises with how the lines connect between data points, resulting in unintended line patterns. The graph appears to create new lines upon fetching new data rather than refreshing them properly. This is causing inconsistencies in the graph display.

If you would like to see more details regarding the issue, check out this Example GIF showcasing the problem in action.

Currently, I'm uncertain about what exactly may be causing this behavior. Although the chart is functional and accurately represents the data, there are concerns about how the lines are connecting between different data points, as highlighted in the GIF demonstration.

Answer №1

The reason for this behavior is that 20 data points are being pushed in onRefresh() every second, but only one of those points is actually new while the rest are duplicates. Because this plugin does not deduplicate data even if it has the same timestamp, you end up with the line chart repeatedly iterating over the same points.

An alternative solution would be to keep track of the latest timestamp in your array when inserting data, and then filter out any old data during the next onRefresh call to ensure that only new data is added to chart.data.datasets[0].data.

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

Issue with Google map displaying incorrectly when attempting to print

I am experiencing an issue with printing a Google Map using the JavaScript API V3. The problem I am facing is that the map is split into two parts, with the top and bottom sections overlapping each other. Here is the code snippet: var geocoder; var ...

Using AJAX and FormData to Attach a List upon Submission

I am currently working on connecting a list of "Product Specifications" to my "Add Product" dialog, and I'm using AJAX to submit the form. Since users are able to upload a product image within this form, I am sending the AJAX request with a 'For ...

Please enter data into the input fields provided in the text

Below is the code where Google transliteration is used for typing in Indian language in a text field. There are two routes with different page IDs. Initially, the transliteration works fine on the default page. However, when changing routes, an error occur ...

Tips for executing jsfiddle code within Joomla 3.2

I'm having trouble executing this code on my Joomla website. I have Joomla 3.2 installed with the JCK Editor, but the HTML tags are not functioning correctly. Can someone please assist me in running the following code: $("#text10").keyup(functio ...

Select the Best jQuery Package

Having a variety of packages available for selection. <div class="image-grid-item" data-search="select"> <input name="pack1" type="checkbox" style="display: none;"> </div> <div class="image-grid-item" data-search="select"> <inp ...

Error: Typically encountered when trying to bind a live event to an undefined object

While developing an application in PHP with AJAX functionality, I encountered a problem specific to Internet Explorer (tested on version 8.0.6001.18702). However, the application works perfectly fine on browsers like Firefox, Chrome, and Opera. The specif ...

Toggle Checkbox Group for Both Multiple and Single Selection Options

Need help with a function to enable only one checkbox for single selection or multiple checkboxes for multiple selection. Use MultipleCheckbox(0) for single selection or MultipleCheckbox(1) for multiple selection. function MultipleCheckbox(elem){ i ...

"Troubleshooting JQuery: Dealing with Errors in Ajax Get

I'm attempting to make a call to a PHP script using a GET request and passing the data theaddress, but the results are displaying the source code of the page I'm trying to call. The page I'm trying to call can be found here. Here is my AJAX ...

The v-tab-item content is not loading properly when the component is initialized in the mounted hook

I'm working on a project that utilizes Vuetify tabs to showcase two different components under separate tabs. The problem I'm encountering is that, within the mounted() function, when attempting to access the refs of the components, only the ref ...

Receiving a commitment from an Angular Resource

When working with $resource in Angular for CRUD operations, I'm encountering some confusion regarding the usage of different resource methods. From what I've observed, the "regular" methods like save() and get() appear to execute synchronously. ...

Using JavaScript, capture the current date and time and store it in a .txt file with the corresponding format

Objective: Upon clicking the download link, an automatically named file will be downloaded with today's date and time format. For example, 7-3-2021 04:04:00 PM or any applicable format with the date and time included in the name. Below is the code sn ...

Managing nested levels in Vue Draggable

Here is a link to the code sandbox: Nested Draggable Code Sandbox The nesting in this code is controlled through directives, specifically using v-if: <template> <draggable class="dragArea" tag="ul" :list="tasks" :g ...

Sharing environment variables between a React app and an Express.js server that hosts it as a static site can be achieved by setting

My static site react app is hosted under an express server project in a folder called client/build. The oauth redirect uris point to the express server for token retrieval. The react app redirects users to the oauth endpoint, which is also referenced by th ...

Issue with Angular table display cell overloading(produces excessive rendering of cells)

In my project, I am working with 3 arrays of data - DATA_CENT, DATA_NORTH, and DATA_WEST. Each of these arrays contains another array called data, which I need to extract and display in a table format. For each new column, I create a new table and then po ...

Suggestions to reduce our website loading time

Query: How can one effectively reduce the file size of a webpage to improve loading speed? What specific optimization practices and coding techniques (in JavaScript and PHP) can be implemented to decrease page weight? Motivation: After reading an article ...

Performing mathematical operations on two arrays in PHP, considering both the keys and values

In the world of a web-based game, imagine two interconnected buildings. The second building acts as an upgrade to the first, but its exact function is not crucial for our purposes. Each building has an experience level that depends on the materials it pro ...

The AutoFill extension on Chrome is failing to update the values of the ng-model

I created a custom chrome extension using jQuery to automatically fill in values on my Angular app. However, the modal values are not being updated. How can I update the modal values? In my content.js file, I have the following code snippet: $(document). ...

The parent component is ignoring the emitted event from the child

I recently built a form component called Form.vue that is nested within PostPage.vue. In the 'Form.vue' component, I am trying to trigger a $emit event to notify the parent component and update a Prop value called btn-text. Parent Component Post ...

What is a method to pull out numerical values from a text in JavaScript without the use of regular expressions?

Consider this scenario: I have a string "asdf123d6lkj006m90" and I want to extract the values [123, 6, 0, 0, 6, 90]. My attempt so far is as follows: let str = "asdf123d6lkj006m90" let func = function(inputString){ let outputArray = [] le ...

What causes the "node: bad option" error to occur when I include a custom flag in the nodejs command line within an Angular 9 application?

Seeking assistance with adding a custom flag to the npm start command in an Angular 9 project. The goal is to intercept proxy requests within the local server and manipulate data. However, encountering the "node: bad option" error consistently. Looking for ...