Highcharts is hitting the limit of the call stack when trying to set

I'm currently working with highcharts and facing an issue where I want to click on a point, trigger a modal pop-up, and be able to change dropdown options as well as the color and symbol of the selected point. While I can successfully change one point, clicking on the next one causes an error: Uncaught RangeError: Maximum call stack size exceeded. Any assistance in resolving this would be highly appreciated!

var update;
// Function for handling point click event
function showModal(p) {  
    update = p;
    var d = moment(p.point.x).format('M/D/YYYY H:mm');
    $('#point-date').html(d);
    $('#point-value').html(p.point.y);
    $('#point-flag').val(p.point.flag);
    $('#pointModal').modal('show');
}

// Handling save action on the modal
function saveFlag() {

    var newData = update.point.series.data;
    var dataPoint = newData.filter(function (r) {
        return r.SiteID == update.point.SiteID && r.Date_Time == update.point.Date_Time
    });
    if (dataPoint != null && dataPoint.length > 0) {
        var size = 2;
        if (data.length < 50)
            size = 4;

        var value = $('#point-flag').val();
        dataPoint[0].marker.radius = size;
        dataPoint[0].marker.symbol = getSymbol(value);
        dataPoint[0].colorIndex = getColorIndex(value);
        dataPoint[0].flag = value;

        for (var index in timeseries.series) {
            if (timeseries.series[index].name == update.point.series.name) {
                timeseries.series[index].setData(newData);
            }
        }
    }
    $('#pointModal').modal('hide');
}

Answer №1

From what I gather, in this scenario the variable timeseries.series is referencing an array within this API. When iterating over an array, it's recommended to use for...of instead of for...in, as for...of will return each element individually:

        for (var series of timeseries.series) {
            if (series.name == update.point.series.name) {
                series.setData(newData);
            }
        }

Further reading:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

Answer №2

I successfully managed to implement an update functionality for a data point.

let updatedData = update.point.series.data;
for (const index in timeseries.series) {
    if (timeseries.series[index].name === update.point.series.name) {
        for (const pointIndex in timeseries.series[index].data) {
            if (timeseries.series[index].data[pointIndex].SiteID === update.point.SiteID
                && timeseries.series[index].data[pointIndex].Date_Time === update.point.Date_Time) {
                    let value = $('#point-flag').val();
                    timeseries.series[index].data[pointIndex].update({
                        marker: { radius: 4, symbol: getSymbol(value) },
                        colorIndex: getColorIndex(value)
                    });
            }
        }
    }
}

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

establishing status within enclosed reaction

In the process of developing a react application, I am encountering difficulties in correctly setting the state with the nested response data received from an api. The state is not aligning as desired. Here is the sample response obtained from the api: [ ...

How can I design unique navigation menus using HTML, CSS, JavaScript, and jQuery?

Is there a way to create menus where clicking on a holiday/seasonal category opens up all related lists automatically? For example: https://i.sstatic.net/Nctd1.png I've been searching online for submenu options but haven't found the right metho ...

Managing Cross-site Request Forgery and Cross-origin Resource Sharing in Django (REST Framework)

We are currently in the process of transitioning our frontend to a separate project outside of Django. This project will be a JavaScript single page application. One of the main reasons for this move is to simplify the workflow for our frontend developers ...

Can you add links or buttons to the page view using Directus v9?

In my Directus 9 project, I have a table dedicated to contacts that includes their emails and a special button leading to an external site. I am wondering if it is possible to make the email address clickable (as a mailto: link) and still display the spec ...

Trying to set headers in Node/Express after they have already been sent is causing an error

I am attempting to send form data from the client side using jQuery to a POST route that will then pass the data to an API in Node/Express. I am encountering an issue where I receive the error message "Can't set headers after they are sent" and I am ...

Enhancing Angular 5 with CustomEvent Polyfill for JavaScript

After implementing the code snippet in main.ts file, I encountered an issue with CustomEvent not being added to the window object correctly. Strangely, when I manually add CustomEvent using the JavaScript console, it works fine. This problem arises specifi ...

What methods can be utilized to accurately determine a user's online status without continuously sending AJAX requests to the server through setInterval?

Seeking effective methods to determine a user's online status I am currently employing an inefficient technique to address this issue: I continuously send AJAX requests to the server at set intervals using setInterval, allowing the server to gauge th ...

Activate tooltip by clicking outside of the dropdown menu

I am experiencing an issue with a tooltip and a dropdown menu. Whenever I interact with the dropdown by clicking outside of it or inside its contents, the tooltip content is triggered again. For example, when I hover over the button, the tooltip triggers ...

"Modify marker icon upon click event in Google Maps by utilizing the loadGeoJson function

I have successfully loaded the markers from a json file using loadGeoJson. While I am able to SET the marker icon/img on load, I am unsure of how to CHANGE it upon click. Is there a way to target the clicked marker and perform a setIcon or similar action ...

Using the forEach method, we can create multiple buttons in ReactJS and also access the onClick handler

I have a button with both the label and onClick properties. Additionally, I have an array containing the values I need to assign to the label property. Here is the code snippet: render(){ {tabel_soal.forEach(function (item, index) { <Ra ...

Node.js is being utilized to upload data to an FTP server with the help of js

I'm attempting to send a file to an FTP server using Node.js with the help of jsftp module.exports = async function() { const jsftp = require("jsftp"); console.log(__dirname) const ftp = new jsftp({ host: "host.name", ...

What is the best way to make an ajax commenting system function from a separate directory?

I am facing an issue with implementing an ajax commenting system on my website. When I place all the code from the /comment directory directly in the root, everything works fine and the commenting system functions as expected on new pages. However, when I ...

Issue with Custom Directive: Receiving Token Error for Expression in Isolated Scope in Angular

(The following messages, code snippets, etc, have been slightly altered for clarification) The error message received is as follows: Syntax Error: Token 'promiseObject' is unexpected, expecting [:] at column 3 of the expression [{{promiseObject ...

Creating enduring designs in Next.js

I've been diving into this amazing article and I'm puzzling over the implementation of persistence in Option 4. It seems like you would need to redefine the .getLayout method for each page. I'm uncertain about how nesting logic is handled fo ...

Learn the process of converting Null values to empty strings within a chain of functions when manipulating a database

Currently, I am utilizing the lodash library and have the following code in place: data: _(responseData.data) .pick(['title', 'layout', 'slug', 'author', 'seo', 'css', 'js']) ...

How can you replicate a mouseover event using Selenium or JavaScript?

I have recently been working on a task involving web UI automation using Selenium, Javascript and SeLion. My goal is to capture a screenshot of a scenario similar to the Google homepage, specifically focusing on the "Search by voice" feature when hovering ...

Switch out the Angular panel with a simple click event

I have developed an angular application using bootstrap. You can view the app on this plunker link <div class="panel col-lg-3 col-md-3 col-sm-2"> <div class="" id="menu"> <div ng-controller="mylistcontroller" cl ...

Using Puppeteer to Retrieve a List of Items with Identical Selectors

Issue: I am currently working on developing an end-to-end regression test for an EmberJS solution using NodeJS/CucumberJS/Puppeteer. However, I have encountered a challenge that I need help with. Challenge: The problem lies in selecting (page.click) and ...

Retrieve the text value of a selected option in a v-select component

After reading some documentation about v-select and slots, I am a bit confused about whether it can be applied to my specific scenario on this codepen. All I really need is to capture the selected text (not the value) and utilize it somewhere in the code: ...

Disregard keys with null values when making a post request using react and axios

As a beginner in JavaScript, I am facing an issue where I do not want to include keys with null values when sending metadata. For example, I should only send the filepath as it has a value, and omit tags and owner which are null. How can I achieve this? ...