Trouble with Highchart.js when passing an array

Currently experimenting with highchart.js.

Here is the code snippet:

$.ajax({    type: "POST",
           url: "api/getListWeight",
           dataType: "json",
           data : {idBoxeur : idBoxeur} 

       }).done(function( dataWeightList ) {

           var data = [];

           $.each(dataWeightList, function( dataWeightList_index, dataWeightList_value ) {

              var splitDateRes = dataWeightList_value.weight_date.split("/");
              data.push("["+Date.UTC(splitDateRes[2],parseInt(splitDateRes[1], 10)-1,parseInt(splitDateRes[0], 10))+","+dataWeightList_value.weight_poids+"]");

           });

           var serie = data.join(",");

       }

The output of the code snippet resembles this:

[1330300800000,76.8],[1347235200000,78.8],[1347580800000,77.4]

exactly as expected.

Now moving on to creating the chart

$('#graph').highcharts({
    chart: {
        type: 'spline',
        zoomType: 'x'
    },
    xAxis: {
        type: 'datetime'
    },
    series: [{
        name: 'serie Name',
        data: [
                //pass in the 'serie' variable from above snippet
                serie
        ]
    }]
});

Issue: no chart displayed. The chart remains empty.

I am certain that replacing serie with

[1330300800000,76.8],[1347235200000,78.8],[1347580800000,77.4],[1348444800000,76.8]
inside the code leads to it working perfectly.

Where am I going wrong? Any suggestions for a solution?

Thank you for your attention.

Answer №1

You are currently passing a string instead of a JavaScript object.

This specific line of code:

data.push("["+Date.UTC(splitDateRes[2],parseInt(splitDateRes[1], 10)-1,parseInt(splitDateRes[0], 10))+","+dataWeightList_value.weight_poids+"]");

should be written like this:

data.push([Date.UTC(splitDateRes[2],parseInt(splitDateRes[1], 10)-1,parseInt(splitDateRes[0], 10)),dataWeightList_value.weight_poids]);

As for the following line of code:

var serie = data.join(",");

What is the purpose of this line? Consider removing it entirely or at least removing the join function.

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

angular.js:13920 Alert: [ngRepeat:dupes] Multiple occurrences in a repeater

I encountered an issue while attempting to parse a JSON file and map it in HTML. Here is the JavaScript code snippet: searhController.orderlogs.results = JSON.stringify(response.data); This is how it's implemented in Angular: <tr ng-hide="searh ...

Problem encountered with a live graph connected to a MySQL database

I've been trying to display a real-time chart using the canvasjs library and connecting to a MySQL database, but I'm encountering some issues. After receiving data for a few minutes, I face the following problem: [ The data I need to sho ...

Issue with Apollo Client - Mutation failing due to undefined property 'data'

When attempting to call a mutation on the client side in Next.js, I encounter an error every time I use the useMutation hook or the client itself, resulting in the following error: Cannot read property 'data' of undefined. See the code snippets b ...

Shuffling elements of an array in C

I previously posted without formatting or adding my code. Let's say I have an array x = [1,2,3]. For a given value i, I want to create an array x^i, where for example, if i = 3, array x^i = [1,1,1,2,2,2,3,3,3]. And if i = 5, array x^i = [1,1,1,1,1,2,2 ...

The search engine results page (SERP) is only displaying the homepage and not any of the subpages

Check out this search to see that only my main page is indexed. Why aren't Google and other search engines picking up arda-maps.org/about/ and the other subpages? Is my deep linking technique incorrect? Do the search engines just need more time? If s ...

Managing a collection of objects within another object

Consider the following two classes with a focus on simplicity for clarity (no sanity-checking of variables etc): <?php class Person { private $Name; private $Phones = []; // List/array of phone number. function __construct($ ...

Using Javascript to retrieve form data from a separate file

I am struggling with my HTML and JavaScript files to collect data. Despite my efforts, the function is not executing properly. Below is the code I have been working on: HTML File : <form class="form-newsletter"> <div class="form-group"> ...

Is there a cutting-edge javascript/jquery tool that enables SQL-type queries on JSON datasets?

About a year ago, this question was posed on Stack Overflow. After searching extensively for answers, it seems that all the libraries I've come across have not been updated in over a year. I'm curious if anyone knows of any currently maintained l ...

Tips for managing page navigation and incoming links on a site that uses only ajax technology

Currently, I am in the process of developing a fully ajax-based website which presents a challenge - the inability to provide direct page links. To address this, I have implemented a functionality where the page name gets appended to the URL each time an a ...

Blending ASP.NET Core 2.0 Razor with Angular 4 for a Dynamic Web Experience

I am currently running an application on ASP.NET Core 2.0 with the Razor Engine (.cshtml) and I am interested in integrating Angular 4 to improve data binding from AJAX calls, moving away from traditional jQuery methods. What are the necessary steps I need ...

What is the best method to access and raise a custom error across all components in Angular?

Incorporating a custom error into Angular is a task I am looking to achieve. My goal is to create a personalized error that can be easily thrown in any part of Angular, whether it be a service, controller, or elsewhere. I don't want to have to go thro ...

After subscribing, my Angular template fails to refresh

Currently, I am facing an issue with my Angular 17 project where the data fetched from the API is not updating the template. This means that despite receiving the data, I am unable to display it on the page. The code snippet below shows the service compon ...

The method subprocess.stdout.on in Node.js does not work as expected

How can I load the result from exec by stream in nodejs/Vuetify.js? In nodejs: const child_process = require('child_process'); _execPull(location){ try{ return child_process.exec('docker pull '+location); }catch(error) ...

React button onclick event not triggering - separate JavaScript file not executing

I have written the code with a separate script file. However, when I click on the buttons next or before, the function nextPrev does not work as expected. All of the JavaScript codes are inside the useEffect, and I am uncertain if this approach is correct. ...

What is the process for choosing a category in the freebase search widget?

For my current project, I have been utilizing the Freebase Search Widget. It allows me to select words from a suggestion list in my input box. However, I am curious about how to also obtain the category in another text box. Here is an example that demonst ...

Implementing React routing with AntD's horizontal menu: a step-by-step guide

I have the main layout component displayed below. I am looking to enable navigation to the home, holiday calendar, and event pages when a menu item is clicked. How can I achieve this functionality with the horizontal menu provided in the code? The main l ...

Having difficulty inputting password for telnet login using Node.js

When I use telnet from the Windows command line, everything works smoothly: > telnet telehack.com (... wait until a '.' appears) . login username? example password? (examplepass) * * * * * * * Logged... (...) @ (This is the prompt when you ...

Embedding Views in a <td> tag with DataTables and Ember.js

Has anyone ever attempted to incorporate a view within a using data tables? Currently, I am loading the data and dataTables through didInsertElement. Within each record, I am adding an "edit" and "delete" button inside a td so users can click to edit or d ...

Retrieve data from cookies that have been stored by the node server on the front end

I am currently utilizing the Node package 'cookie' to establish cookies from the backend as shown below: res.setHeader('Set-Cookie', cookie.serialize('token', token, { maxAge: 60 * 60 * 24 * 7 // 1 week ...

Deleting elements from an array in AngularJS based on their ID

Is there a way in Angular to easily remove specific items from an array based on comparison criteria? For example, if I have an array of people and want to remove certain individuals by their ID or another property. I'm looking for a solution that doe ...