Synchronize all series in Highcharts charts simultaneously

I have implemented the following code to showcase a Highchart with 3 signals, which are updated periodically with animation. However, I am facing an issue where, for 2 of the signals, the dots are updated first and then the curve slides into the dots. This results in a jumpy transition when multiple signals are displayed. On the other hand, when I only display one signal, the visualization looks smoother as the dots never appear to "jump" out of the curve. Could someone provide guidance on how to update all curves without encountering this jumping effect?

    <!DOCTYPE html>
    <html lang="en">
    <head>
    </head>
      
    <body>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>


    <script type="text/javascript">
    
    $(document).ready(function () {
      function initData()
      {
        var data = [];
        var time = Date.now();
        for (var i = -60; i <= 0; i += 1) {
            data.push({ x: time + i * 1000, y: 0 });
        }
        return data;
      }

      Highcharts.chart('container', {
        chart: {
        type: 'spline',
        animation: { duration:500}, //false,
        events: {
          load: function () {
            var series = this.series;
            var len  = series.length;
            setInterval(function () {
              var t = Date.now();
              for (var j = 0; j < len; j++) {
                series[j].addPoint([t, Math.random()], true, true);
              }  
            }, 1000);
          }
        }
        },
        title: {text: 'Live random data'},
        xAxis: {type: 'datetime', tickPixelInterval: 150 },
        yAxis: {title: {text: 'Value' }, plotLines: [{value: 0, width: 1, color: '#808080'}] },
        legend: { enabled: false },
        exporting: { enabled: false },
            series:
            [
              { name: 'Random data', data: initData() },
              { name: 'Signal2', data: initData() },
              { name: 'Signal3', data: initData() }
            ]
        });
    });
    </script>

    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <div id="container" style="min-width: 310px; height: 500px; margin: 0 auto"></div>

    </body>
    </html>

Answer №1

After reviewing the API documentation, it clearly states that when adding points, setting the redraw parameter to false and then explicitly calling Highcharts.Chart#redraw after all points have been added is recommended.

redraw Boolean

Whether to redraw the chart after the point is added. When adding more than one point, it is highly recommended that the redraw option be set to false, and instead Highcharts.Chart#redraw is explicitly called after the adding of points is finished. Otherwise, the chart will redraw after adding each point.

By making sure that redraw is only done once after all points are added, your issue should be resolved.

load: function () {
  var series = this.series;
  var len  = series.length;
  setInterval(function () {
    var t = Date.now();
    for (var j = 0; j < len; j++) {
      series[j].addPoint([t, Math.random()], false, true); //set redraw to false
    }
    chart.redraw(); //added a redraw here
  }, 1000);
}

Here is a working example: https://jsfiddle.net/ewolden/q489nsgw/4/

For more information on addPoint in the API: http://api.highcharts.com/class-reference/Highcharts.Series#addPoint

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

Node.js has the ability to establish internal connections, however it cannot establish connections

I'm having an issue connecting to a JavaScript file on my local server. I'd like to input the external IP address and port in order for it to run externally. This functionality currently works when accessed locally. Below is the code from my serv ...

The div element fails to display even after invoking a JavaScript function to make it visible

As a newcomer to JavaScript & jQuery, please bear with me as I ask a very basic question: I have created the following div that I want to display when a specific JavaScript function is called: <div id='faix' class="bg4 w460 h430 tac poa ...

Firebase Hosting is not compatible with Express session

After setting up my code as shown below, I noticed that sessions are being persisted and the page is able to count the number of visits. app.set('trust proxy', true) // The documentation specifies '1' instead of 'true' app.u ...

Unable to shake off a sudden burst of information following the ajax page load

I am facing an issue with my page that involves making different ajax calls based on user clicks. There are four IDs, and only one should be visible at a time. However, when new ajax content is loaded into a div, I experience a brief flash of the previou ...

Tips for setting React state using variables as keys or values

Although I managed to achieve the desired result, I'm still puzzled as to why my more straightforward approaches didn't work. Can someone help me understand what's going on here? Basically, I needed to set nested state at different levels u ...

JavaScript Conversion from Binary to Decimal

This code is meant to convert a binary string ("100101") to its decimal equivalent. I am struggling to identify the issue causing it to not work properly. Any assistance would be greatly appreciated. function BinaryConverter(str) { var num=str.split("") ...

Error: The JSON in app.js is invalid due to the unexpected token "C" at position 0

When I try to run this code snippet, I sometimes encounter an error message that says: SyntaxError: Unexpected token C in JSON at position 0. function fetchData(user_country) { fetch(`https://covid19-monitor-pro.p.rapidapi.com/coronavirus/cases_by_day ...

Error in AWS Lambda: JSON parsing error due to unexpected token 't' at position 6

I'm currently working on a basic lambda function that utilizes a post request to insert data into DynamoDB. However, every time I deploy the lambda function and test it using Postman, I keep encountering a 502 Bad Gateway error. To troubleshoot this ...

Delaying the intensive rendering process in Vue.js and Vuetify: A comprehensive guide

Recently, while working on a project with Vue.js 2 and Vuetify 2.6, I encountered an issue with heavy form rendering within expansion panels. There seems to be a slight delay in opening the panel section upon clicking the header, which is most likely due t ...

The value retrieved from the event handler function's state does not match the anticipated value

While debugging, I often minimize this particular component to understand its behavior later on. It was quite challenging to pinpoint the issue due to some intricate logic in place. Nonetheless: import { useContext, useEffect, useState } from "react&q ...

Issue with Framework7: Swiper slider link not functional

On one of the slides in my swiper slider, there is a link that redirects to a file named year.html Here is the link: <a href="year.html">Add by year, make & model</a> Source code for swiper slider: http://pastebin.com/ggN3TqgA Content ...

Exploring the Depths of Google Chrome: Unleashing the Power of

While a similar question has been posed previously, I am encountering difficulties debugging Javascript in Google Chrome. When I navigate to Page > Developer, the "Debug Javascript" function (Ctrl+Shift+L) is not active. Even trying Alt + ` does not se ...

How can we display a fallback image if the Iframe is unable to load the resource at src in AngularJs?

In one of my JSP pages, I am utilizing an iframe and I want to set an external address as the src of this iframe. Typically, everything works fine. However, in cases where the external source is unavailable, I want to display a static image instead. I&apos ...

Insufficient image quality on mobile when using HTML5 canvas toDataURL

I've encountered an issue with the toDataURL("image/png") function. My canvas contains various lines, colored shapes, and text. While the resulting png image appears sharp on desktop Chrome, it becomes pixelated and low quality when viewed on mobile C ...

Adjusting the width of a product slider based on window size changes using CSS media queries

Currently, I have a functional product slider that I am attempting to adjust the width for smaller viewports, but it is proving to be a challenge. Upon loading the document, the code tallies the width of each product item and initiates slides when buttons ...

Tips for creating text that changes size based on the container dimensions

I am looking for a way to ensure that the content within a div container remains neatly contained without overflowing. How can I make the container responsive so that it adjusts its size based on dynamic text? .element { display: inline- ...

The post request fails to send certain variables

I'm experiencing an issue with a form that has rows structured like this: <div class="row unit" onmouseover="this.style.background = '#eeeeee';" onmouseout="this.style.background = 'white';" onclick="if(event.srcElement.nodeNam ...

If other options fail, Else If may not be a suitable choice

This is the process: switching from Issue: x==0||1 to x==0||x==1 etc. This code runs from an .html file <body> <div class="" id="pimg1"> </body><script> var x=new Date().getMonth(); if (x == 0||x == 5||x == 2){docu ...

Having trouble sending a cross-domain request within a `Firefox` extension

I have been attempting to access data from a different domain using either jsonp or XMLHttpRequest with a GET method. Here is my code: XMLHttpRequest var xhr = new XMLHttpRequest(); xhr.open("GET", "http://example.com/ajax.php?code=BSE", true); xhr.onrea ...

Creating nested tables by assigning unique Div IDs to each table element

Can we utilize a straightforward JavaScript/jQuery function to nest elements inside table elements? For instance, every square comes with its own unique ID (A1, B7, C5). How can I use this ID to insert the checker image in any selected tile upon clicking? ...