The historical records in highcharts do not include the millisecond data

One issue arises when dealing with a large amount of data in highcharts' historyData - upon zooming, the data is only present at one-second intervals, rather than milliseconds. This results in missing millisecond data when zoomed in on a chart with substantial history data.

To replicate this issue, please visit the provided link and wait until there is a significant dataset in the historyData. Then, adjust the interval in the setInterval method from 20 to a larger number like 20000. Upon zooming in using rangeselector, you will notice that only second data is plotted, while millisecond data is absent.

This issue can be seen in action here: https://jsfiddle.net/nh5ap21m/

I have referred to the Highcharts API documentation: https://api.highcharts.com/highcharts/plotOptions.series.pointInterval and experimented with various parameters such as pointInterval, pointIntervalUnit, connectNulls, gapSize, and gapUnit, but have yet to find a definitive solution.

To change the interval, use the following code:

setInterval(function () {
                    var x = (new Date()).getTime(), // current time
                        y = Math.round(Math.random() * 100);
                    series1.addPoint([x, y], true, true);
                }, 20);
                var series2 = this.series[1];
                setInterval(function () {
                    var x = (new Date()).getTime(), // current time
                        y = Math.round(Math.random() * 50);
                    series2.addPoint([x, y], true, true);
                }, 20);

Expected Result: When zoomed in on the historyData of the chart, both seconds and milliseconds data should be plotted accurately.

// Create the chart
Highcharts.stockChart('container', {
    chart: {
        events: {
            load: function () {

                // set up the updating of the chart each second
                var series1 = this.series[0];
                setInterval(function () {
                    var x = (new Date()).getTime(), // current time
                        y = Math.round(Math.random() * 100);
                    series1.addPoint([x, y], true, true);
                }, 20);
                var series2 = this.series[1];
                setInterval(function () {
                    var x = (new Date()).getTime(), // current time
                        y = Math.round(Math.random() * 50);
                    series2.addPoint([x, y], true, true);
                }, 20);
            }
        }
    },

    time: {
        useUTC: false
    },

    rangeSelector: {
        buttons: [{
            count: 1,
            type: 'minute',
            text: '1M'
        }, {
            count: 5,
            type: 'minute',
            text: '5M'
        }, {
            type: 'all',
            text: 'All'
        }],
        inputEnabled: false,
        selected: 0
    },

    title: {
        text: 'Live random data'
    },

    exporting: {
        enabled: false
    },
legend: {
                enabled: true
            },
plotOptions: {
        series: {
            marker: {
                states: {
                    hover: {
                        enabled: true,
                        animation: {duration: 100},
                        enableMouseTracking: true,
                        stickyTracking: true
                    }
                }
            }
        }
    },

tooltip:{
shared: true,
                split: false,
  stickyTracking: true,
                enableMouseTracking: true,
                enabled: true,
                followPointer: true,
                followTouchMove: true,
    formatter: function(){
                var tooltip = "";
                var phaseNameList = "";
                
                //tooltip += "<b>I-unit "+ "<br/>"+ "x: "+this.x +"</b>";
                tooltip += "<b>I-unit "+ "<br/>"+ "x: "+ new Date(this.x)+
                "</b>";
                tooltip +=  "<br/>"+ "y: "+this.y +"</b>";
                tooltip +=  "<br/>"+ this + "</b>";
                return tooltip;
               }
},

    series: [{
        name: 'Random data1',
        data: (function () {
            // generate an array of random data
            var data = [],
                time = (new Date()).getTime(),
                i;

            for (i = -999; i <= 0; i += 1) {
                data.push([
                    time + i * 1000,
                    Math.round(Math.random() * 100)
                ]);
            }
            return data;
        }())
    },
    {
    name: 'Random data2',
        data: (function () {
            // generate an array of random data
            var data = [],
                time = (new Date()).getTime(),
                i;

            for (i = -999; i <= 0; i += 1) {
                data.push([
                    time + i * 1000,
                    Math.round(Math.random() * 50)
                ]);
            }
            return data;
        }())
    }]
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>

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

Answer №1

One key distinction lies in the time interval of the initial data:

for (i = -999; i <= 0; i += 1) {
    data.push([
        time + i * 1000,    // timestamp every second
        Math.round(Math.random() * 100)
    ]);
}

In contrast, the dynamically added data follows a much shorter 20 milliseconds interval:

setInterval(function() {
    var x = (new Date()).getTime(), // timestamp every 20 milliseconds
        y = Math.round(Math.random() * 50);
    series2.addPoint([x, y], true, true);
}, 20);

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

Tips for addressing flickering issues when scrolling on your device

I am facing an issue with two elements that are set to a fixed position on the page. When these elements reach the bottom of the page, I want them to revert back to a static position using JavaScript. The problem occurs when trying to scroll by clicking a ...

Constantly loading image with Meteor HTTP request

Within my Meteor application, I am attempting to dynamically load a random image from an API which returns JSON data structured like this: { "id":2026 "url": "https:// ... " , "large_url":null, "source_id":609, "copyright":"CC0", "site":"unsplash" } ...

Receive a response in fragments from express on the browser

As I work on creating a progress bar to track long-running server-side tasks that may take up to a few minutes, I am exploring different methods to display the progress of each task. While WebSockets and interval polling are options, I prefer using long-po ...

Simplify your code with promises in JavaScript

Running on an API with node v6.3.0, I have the following code that executes two separate promises based on a conditional check for a parameter in a POST request. if (paramExists) { // query database with this condition User.filter(/* utilize param ...

Do I need to include success as a parameter in my Ajax call even if my function does not return any values?

When an image is clicked, I trigger an ajax call. The image includes an href tag that opens a different page in a new tab upon click. The purpose of this ajax call is to record the user's clicks on the image for telemetry purposes in a database table. ...

A guide on sharing an express.js response object with a different module

In my server.js file, I am attempting to pass an Express response object to a different module. Here is how I have implemented it: const room = require('../controller/rooms_controller') app.post('/rooms', function(req, res){ var na ...

Utilizing jQuery on the newly inserted <tr> element

I have created a jQuery code that includes 3 pre-existing rows with a text box to add more similar rows. The jQuery functions are initially applied to the first 3 hard-coded rows. I am looking to extend this functionality to dynamically added rows later on ...

When using JSON stringify, double quotes are automatically added around any float type data

When passing a float data from my controller to a JavaScript function using JSON, I encountered an issue with quotes appearing around the figure in the output. Here is the JS function: function fetchbal(){ $.ajax({ url: "/count/ew", dataType: "jso ...

Using Javascript to save a numeric value and accessing it on a different webpage

I'm encountering an issue with a specific feature on my website. I want users to click on a hyperlink that will redirect them to an application form page. The challenge is ensuring that the reference number (a 5-digit code displayed as a header) is st ...

Dealing with incorrect routes found in both documents

In my current project, I am facing an issue where I need to handle invalid routes and display a message in Node.js. I have two separate files, one for users and one for tasks. If a user accesses a route that does not exist, I want to show an error message ...

Dynamically validate AngularJS forms with JSON Schema

I am currently trying to dynamically validate JSON in AngularJS. Unfortunately, I have encountered an issue with loading fields from the schema onto the page. My understanding of AngularJS is limited as I am still new to it. Although I have managed to cr ...

Indicate the highest value on Amcharts by drawing a line

I am currently working on plotting a graph that involves a significant amount of data. I have around 96 plots per day, and users can fetch data for up to a maximum range of 62 days. To implement this, I am utilizing Amcharts, but I have encountered an issu ...

What is the method to adjust the anchor point for a MUI popover?

I currently have the following code for handling a popover: const [open, setOpen] = useState(false); const anchorRef = createRef() const handleClose = () => { setOpen(false); }; const handleClick = useCallback( (event: MouseEvent<H ...

"Here's a simple guide to generating a random number within a specified range

I have encountered a specific issue: Within an 8-column grid, I am attempting to randomly place an item with a random span width. While I have successfully managed to position the item and give it a random width, I am struggling with adjusting the width b ...

Issue with filtering of values returned by functions

I've been working with Angular's currency filter and I've run into an issue. It doesn't seem to be filtering the data that is returned from a function. I have a feeling that I might be missing something, perhaps it has to do with how th ...

Selenium webdriver was not able to find the specified div element

Currently, I am working on automating a scenario where a user searches for an item and once the search results are displayed, they click on the serving size and quantity of that specific item. https://i.sstatic.net/GV02V.jpg However, I keep encountering ...

There was a problem encountered while trying to load the .json/.csv file

Attempting to grasp D3 through this video has been a challenging experience, particularly when attempting to load an external file. The code snippets are provided below: index.html <html> <head> <meta charset="utf-8"> <title& ...

Troubleshooting the Connect Button in Chapter 3 of 'Mastering XMPP Development with JavaScript and jQuery'

Currently, I am in the process of setting up an xmpp client on my website and to familiarize myself, I am following the examples provided in a book. Example 3 has been successfully implemented by copying the code, with the only alterations being the stroph ...

How does the position of the scroll affect the height of an element on a webpage

Currently, I'm exploring the 'scroll' eventlistener in web development to incorporate some motion design elements into my projects. For this particular experiment, I am making a div element react to the user's scrolling actions on the p ...

Customize footer data in ui-grid design

I'm having trouble formatting the aggregate value for a column in ui-grid. Currently, the number display looks like this: total: 6370.046074130321 but I would prefer it to be formatted like this: total: $6370.05 I've attempted using both of ...