Ways to prevent endless recurrence in callback functions

I've been struggling to figure out why I keep encountering an infinite recursion issue within the Vue's Vue-charts legendCallback, and I haven't been able to find a solution. Any help would be greatly appreciated.

Within my Vue component, the `options` are defined in the following way:

  options() {
                var self = this;
                 return {
                    legend: {
                        display: false,
                        position: 'top',
                    },
                    legendCallback: chart=> {
                        return this.generateLegendData(chart)
                    },
                    tooltips: {
                        mode: 'single',
                        callbacks: {
                            label: function (tooltipItems) {
                                return "text"
                            }
                        },
                    }
                }
            },

The method I have for generating the legend data looks like this:

        generateLegendData(chart) {
          var labels = ["SolarCity", "Einstein", "SpaceX", "Mars", "Tesla"];
          var backgroundColor = [
            "rgba(242,58,48, 0.1)",
            "rgba(110,75,63,1)",
            "rgba(55,72,172,1)",
            "rgba(0,39,39,1)",
            "rgba(166,176,69,1)"
          ];

          var text = [];
          text.push('<ul class="' + chart.id + '-legend">');
          for (var i = 0; i < labels.length; i++) {
            text.push(
              '<li><span style="background-color:' + backgroundColor[i] + '">'
            );
            if (labels[i]) {
              text.push(labels[i]);
              console.log(labels[i]);
            }
            text.push("</span></li>");
          }
          text.push("</ul>");

          return text.join("");
        }

When I remove the for loop and simply return the expected string, everything functions correctly.

Answer №1

There was no issue with returning return text.join("").

The resolution involves relocating the options attribute from being a method to becoming a computed property.

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

Effectively accessing the Templater object within a user script for an Obsidian QuickAdd plugin

I have developed a user script to be used within a QuickAdd plugin Macro in Obsidian. The Macro consists of a single step where the user script, written in JavaScript following the CommonJS standard, is executed. Within this script, there is a task to gene ...

3D objects must always be positioned to perfectly fit within the window when using an Orthographic Camera

My goal is to ensure that my 3D objects always "fit" inside the window. Here is an overview of my current code: export function onWindowResize(camera, renderer) { const canvas = renderer.domElement; const width = window.innerWidth; const height = win ...

How can you identify errors in serialization when working with Web API endpoints?

There are times when I have an endpoint set up on my web API: [HttpPost] public async Task Foo([FromForm] int[] a, [FromForm] int b, ...) { await Task.Delay(1000); } When I make a call to this endpoint from the client side using axios: var formData = ...

Create eye-catching banners, images, iframes, and more!

I am the owner of a PHP MySQL website and I'm looking to offer users banners and images that they can display on their own websites or forums. Similar to Facebook's feature, I want to allow users to use dynamic banners with links. This means the ...

How to extract various elements from a database array by utilizing .map within a React Component?

I'm currently diving into React and have encountered a challenge when it comes to rendering multiple elements simultaneously. The issue revolves around fetching an Array from Firebase, which is supposed to generate a new div and svg for each item in ...

Tips for removing the current item from a list by clicking on a close icon of the same class name

Is there a way to remove a list item after clicking on its close icon? I am using a JavaScript function to add items to the list. Please refer to the image and code below. Thank you! https://i.stack.imgur.com/aeASd.png The code snippet is as follows: f ...

Why is my React-Redux API Get request action not running?

Hello there! I am currently working on integrating React-Redux with my Flask API to display JSON data on my website. Although the API is functioning properly, I seem to be facing an issue where the action called does not execute. As a beginner in Redux, I ...

How can you incorporate a value into a variable in PHP?

Hey there! I'm pretty new to PHP and I've been working on building a program that resembles a spreadsheet. My form consists of columns and cells, allowing users to add or delete rows using Javascript. The challenge I'm facing is automating t ...

Query regarding JSON format

If I have a database table named User with fields for name, Id, and age, how can I retrieve this data as JSON and send it to a JavaScript page? I want to customize the way the data is displayed on the frontend. Specifically, I need help understanding how ...

Combine several divs into a block of individual divs

As part of my project, I am working on creating a number board where specific numbers need to merge into a single cell. Please see the picture for reference https://i.sstatic.net/99WJq.png Below is the HTML code snippet that I have tried. I used margin fo ...

Animating sprites using TypeScript

I've been tackling the development of a small Mario game lately. However, I'm facing some difficulty when it comes to animating sprites. For instance, I have a mario.gif file featuring running Mario (although he's not actually running in th ...

Updating model/schema dynamically within Express Router

My express server handles api calls by directing them to specific routes. app.use('/api/data01', require('./routes/dataRoute01')) app.use('/api/data02', require('./routes/dataRoute02')) app.use('/api/data03&apo ...

When a form input is submitted, the webpage will refresh with a new

I have a form embedded on my WordPress page. I want to identify users without referrers so that I can set the referrer for them automatically (the referrer part is handled by a plugin). The registration form URL looks like this: The code provided below w ...

Angular - Async function does not resolve a rejected promise

Currently, my component utilizes an async method for handling file uploads. Here is an example: //component uploadPhotos = async (event: Event) => { const upload = await this.uploadService.uploadPhotos(event, this.files, this.urls); } The UploadSe ...

the sequence of events in a web setting

Can you explain the sequence of execution in a web application? The order typically involves PHP, HTML, JavaScript, CSS, and MySQL being executed. ...

Flot seems to be having difficulty uploading JSON files

I am relatively new to working with json and flot, but have been tasked with creating a chart. Can someone please help me troubleshoot why my code is not functioning as expected? $.getJSON('chart.json', function(graphData){ alert(graphData); ...

Error with react/display-name in ESLint when using dynamic imports in Next.js

I encountered an error message from ESLint that says: Component definition is missing display name This error occurred in the following code snippet: const Disqus = dynamic(() => import('@/components/blog/disqus'), { ssr: false, loading: ...

Ways to display information in Vue JS without the need for pagination buttons

Having an issue displaying data automatically in VueJS. Previously, "User Online" data was successfully displayed but now I have to click on the page to show existing data. I want the data to be shown automatically without needing to click on page 1. http ...

Require assistance with debugging an issue in an online game played through a web browser

Experience a simple browser memory game where you must flip all matching cards to emerge victorious. The glitch : In the game, if you click quickly enough, you can uncover more than two cards at a time. I've spent ample time attempting to rectify t ...

Issue with npm package mail-listener2: Attachments not being saved for emails received from Outlook 2016

I am attempting to retrieve attachments from Outlook, saving them in a specific folder as outlined in the configuration: { username: "username@here", password: "password", host: "hostName", port: 993, connTimeou ...