Transforming an array of strings into a visual representation

Having an issue parsing a string array for Highcharts consumption. The chart renders when values are static, but not when passed as an array. I have validated the string being parsed here.

The main issue appears to be with this specific line:

//This works
chart.addSeries({name: this.series_name, color: this.series_color, data: [[0.129, 0.066], [0.029, 0.218], [-0.113, 0.231]]});

//This does not work
chart.addSeries({name: this.series_name, color: this.series_color, data: series_clean});

Code snippet:

$(document).ready(function() {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'scatter',
            zoomType: 'xy'
        },
        series: [
            {data: []}
        ]
    });

    function reloadData() {
        $.ajax({
            type: 'GET',
            url: "...",
            dataType: "JSON"
        }).done(function(data) {
            //Remove existing series from chart
            while(chart.series.length > 0)
                chart.series[0].remove(true);

            var i = 0;
            $.each(data.users, function(firstIndex, user) {
                $.each(user, function() {
                    //Parse incoming data array to float type
                    var series_clean = new Array();

                    var series_data_groups = this.series_data.split("|");

                    for(var j = 0; j < series_data_groups.length; j++) {
                        var series_data_values = series_data_groups[j].split(",");
                        var x = parseFloat(series_data_values[0]).toFixed(3);
                        var y = parseFloat(series_data_values[1]).toFixed(3);
                        series_clean.push([x, y]);
                    }

                    //Push series to chart
                    chart.addSeries({name: this.series_name, color: this.series_color, data: series_clean});
                    i++;
                });
            });

            chart.redraw();
        });
    }

    setInterval(function(){reloadData(); }, 2000);
});

Error in console:

Uncaught Error: Highcharts error #14: www.highcharts.com/errors/14
    at Object.a.error (highcharts.js:10)
    at n.setData (highcharts.js:284)
    at n.init (highcharts.js:277)
    at a.Chart.initSeries (highcharts.js:243)
    at highcharts.js:317
    at a.fireEvent (highcharts.js:29)
    at a.Chart.addSeries (highcharts.js:317)
    at Object.<anonymous> (chart_scatter_live2.html:109)
    at Function.each (jquery-3.2.0.min.js:2)
    at Array.<anonymous> (chart_scatter_live2.html:95)

Answer №1

It appears that your variables x and y are being treated as strings due to the use of toFixed(), which returns a string in this context:

var x = parseFloat(series_data_values[0]).toFixed(3);
var y = parseFloat(series_data_values[1]).toFixed(3);

This can lead to the Highcharts Error #14 - String value sent to series.data, expected Number.

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

Retrieve the color of the TripsLayer in deck.gl

layers.push(new TripsLayer({ id: 'trips', data: trips, getPath: (d: Trip) => d.segments.map((p: Waypoint) => p.coordinates), getTimestamps: (d: Trip) => d.segments.map((p: Waypoint) => p.timestamp), ...

What is the process of caching images when they are loaded through a php script?

My PHP script acts as a random image generator by querying the database for user images and returning a random one. Below is the code snippet responsible for serving the randomly chosen image. header('Content-Transfer-Encoding: binary'); header( ...

Execute the function on the React template rendering process

How can I ensure that the getQuestions function is called when the template questionsCollected is rendered, without relying on an event trigger like onClick? The ajax call successfully retrieves the option items and logs them to the console. The template ...

JavaScript's XMLHttpRequest

My attempt to bypass the WebGoat prompt involved using a combination of javascript code with XMLHttpRequest to send multiple requests, one using GET and the other using POST. The code snippet is as follows: <script> var req1 = new XMLHttpRequest() ...

Alter the value of an input element using JavaScript

There are multiple hidden input fields on the page I'm currently working on: <input a1="2" a2="1" a3="3" name="Value" type="hidden" value="10"> <input a1="4" a2="2" a3="6" name="Value" type="hidden" value="12"> <input a1="6" a2="3" a3 ...

Tips for updating the text shown in an md-select box without affecting the underlying model

Using the Angular material library directive md-select, I have implemented a feature to display country codes to users. When a country is selected, I want to show only the country's dialing code in the select box. For example, if the user selects Ind ...

Removing API request in React.js

My approach: deleteSample = () => { this.sampleService .deleteCall(this.props.id) .then((response) => { window.location.reload(false); }) .catch((error) => { console.log ...

What role does the "deep" parameter serve when declaring a watcher in VueJS?

I recently discovered a feature in Vue.js called watchers while working on my web app. As I was exploring the API documentation, I came across a flag known as deep. This flag caught my attention because it defaults to false. I'm curious to know what s ...

A guide on implementing Angular ngbPopover within a CellRenderer for displaying in an ag-grid cell

I successfully set up an Angular Application and decided to utilize ag-grid community as a key component for displaying data from a backend API in tables, using fontawesome icons to enhance readability. While everything looks fine and my application is fu ...

Choosing a row in a table with ASP.NET by utilizing jQuery on click

After setting up a table in ASP.NET with the feature to select individual rows using a link at the end of each row, I have been able to successfully implement it. The process involves setting a value at the top of the view and then dynamically changing the ...

I am unable to determine if I have already selected a List Item

My goal is to have a functionality where clicking on "Download Drivers" will open the list, and clicking again will close it. This should be achieved with onclick events only, no hover effects. Additionally, I want the list to remain open even if I click o ...

Troubleshooting the "Failed to mount component" error in Vue: fixing template or render function definition issues

Struggling with writing a Vue component, encountering the issue: Failed to mount component: template or render function not defined. Tried various fixes like adding default when importing the component, but none of them seem to work. My component code is i ...

Incorporating a TypeScript module into a JavaScript module within a React application

I'm encountering an issue with my React app that was created using create-react-app. I recently added a Typescript module to the project, which is necessary for functionality reasons. Although it will remain in Typescript, I made sure to install all t ...

How to Use jQuery in Thymeleaf to Toggle All Checkboxes

Why isn't the function of selecting and deselecting all fields working correctly for me? Can anyone explain what may be causing this issue? ..... <head> <meta name="viewport" content="width=device-width, initial-scale=1.0&q ...

.NET Core ViewModel with IFormFile attribute causing AJAX Request to freeze

Users now have the option to upload images for a retail product within an Add/Edit Product modal. Product Modal ViewModel: public class ProductModalViewModel { public ProductModalViewModel() { Product = new ProductDTO(); Images = ...

Modify the CSS using JavaScript after a brief delay

I'm creating a homepage that includes animations. Inside a div, I initially have display: none, but I want it to change to display: block after a few seconds. I've been trying to use JavaScript for this purpose, but I'm struggling to find th ...

A guide on utilizing Puppeteer for capturing screenshots of web pages with embedded videos

Currently, I am using Puppeteer to access a website and capture a screenshot of a video. Unfortunately, the default Chromium browser that Puppeteer uses does not support certain video types. I have managed to get it working by launching Puppeteer with a l ...

Transfer groups between divisions

In my HTML structure, I have two main divs named Group1 and Group2. Each of these group divs contains at least two inner divs, all with the class .grp_item. Currently, the grp_item class is set to display:none, except for one div in each group that has a c ...

Guide to importing a JavaScript module using jQuery

I have been encountering an issue while loading a javascript file using jquery. The code I am working with is as follows: // file application.js $.getScript("module.js", function(data, textStatus, jqxhr) { ... }); Everything seems fine so far. However, t ...

Unable to locate a type definition file for module 'vue-xxx'

I keep encountering an error whenever I attempt to add a 3rd party Vue.js library to my project: Could not find a declaration file for module 'vue-xxx' Libraries like 'vue-treeselect', 'vue-select', and 'vue-multiselect ...