Troubleshooting Problems with Loading Data into Highcharts using Javascript

The server is returning data in the following format:

{"barData":
    [
        {"Accepted":[0,0,0]},
        {"Rejected":[0,0,0]},
        {"In_Process":[0,1,0]}]
}

On the browser, it appears as follows:

I initially thought that this was the correct structure for populating a Highcharts stacked bar chart based on this example:

Example Stacked Bar in jsFiddle

The documentation presents a fixed dataset like this:

series: [{
            name: 'John',
            data: [5, 3, 4, 7, 2]
        }, {
            name: 'Jane',
            data: [2, 2, 3, 2, 1]
        }, {
            name: 'Joe',
            data: [3, 4, 4, 2, 5]
        }]

This is what I aimed to replicate. After all the efforts, I ended up with a zero plot. My JavaScript code looks like this:

$.ajax({
url : 'http://localhost:8080/afta/report/transfersbynetwork',
success : function(point) {
    data = [];
    $.each(point.barData, function(itemNo, item) {
        data.push([ item[0], parseInt(item[1][0]), parseInt(item[1][1]), parseInt(item[1][2])]);
    });
    barchart = new Highcharts.Chart(baroptions);
    baroptions.series[0].data = data;
},
cache : false
});

Where did I go wrong? I'm not seeing any plot and suspect the issue lies in either how I'm presenting the data from the server (possible) or in the JavaScript parsing of the data structure and series loading (highly likely).

Any help or insight would be greatly appreciated.

Answer №1

To implement your data processing function effectively, make sure to adjust it according to the structure provided:

$(function () {
    var point = {
        "barData": [{
            "Accepted": [1, 2, 3]
        }, {
            "Rejected": [3, 4, 5]
        }, {
            "In_Process": [0, 1, 0]
        }]
    },
    data = [];

    $.each(point.barData, function (itemNo, item) {
        for (var prop in item) {
            data.push({
                name: prop,
                data: [parseInt(item[prop][0]), parseInt(item[prop][1]), parseInt(item[prop][2])]
            });
        }
    });
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Stacked bar chart'
        },
        xAxis: {
            categories: ['Apples', 'Oranges', 'Pears']
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Total fruit consumption'
            }
        },
        legend: {
            backgroundColor: '#FFFFFF',
            reversed: true
        },
        plotOptions: {
            series: {
                stacking: 'normal'
            }
        },
        series: data
    });
});

http://jsfiddle.net/9jVJb/

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

Chart featuring top corners smoothly rounded off for a unique doughnut design

I've been attempting to create a D3.js chart similar to the one shown in the first screenshot: https://i.sstatic.net/GgP1d.png While I can easily replicate a chart like the second screenshot using the default examples, the challenge arises when I tr ...

Deliver varied asset routes depending on express js

I have a situation where I am working with express routes for different brands. My goal is to serve two separate asset directories for each brand route. One directory will be common for all brand routes, located at public/static, and the other will be spec ...

Distinguishing div identifiers for jQuery displaying and concealing

Although I am not a coder, I am still learning and trying to improve my skills. I have multiple div elements listed by a MySQL query. I require a JavaScript code that can display the class="qform" div based on which button is clicked. If button-1 is clic ...

Guide to embed a Google Sheets chart into a WordPress website

I'm looking to include a chart in a wordpress post, using the script generated from google sheets' publish function. When I add the script to a generic HTML page, the chart displays properly. However, when I insert it into a wordpress post, I en ...

Steps for creating a personalized query or route in feathersjs

I'm feeling a bit lost and confused while trying to navigate through the documentation. This is my first time using feathersjs and I am slowly getting the hang of it. Let's say I can create a /messages route using a service generator to GET all ...

PHP not displaying line breaks from JavaScript textarea

I am facing an issue while trying to generate a .txt file on my server upon form submission. Despite including newlines in the comment section, they do not show up in the resulting .txt file. Below is the code snippet I am using: Javascript function sen ...

The error message states: "An error occurred: Unable to find the 'HttpProvider' property within an undefined

import * as Web3 from 'web3' import { OpenSeaPort, Network } from 'opensea-js' const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io') Hello everyone, I'm currently learning Node.js and encountered ...

Unable to update content within the `style` attribute when the HTML is stored in a variable

I am attempting to make changes to the style html - specifically by replacing a string, but unfortunately it is not functioning as expected. I am struggling to obtain the final updated html. Below is my attempt: var html = "<style>043BF83A8FB24A418 ...

What is the best way to retrieve chosen "CheckBoxes" from a tree view with JavaScript?

I am currently working with the asp TreeView control and I am interested in obtaining the selected values of "checkboxes" on the client side. Is there a way for me to retrieve the selected values from the TreeView? ...

Mapping JSON representations to domain models with Spring Data REST

I am currently facing an issue while using Spring Data Rest. My Domain Model looks like this: @Entity public class Sample implements Serializable { @Id @GeneratedValue private Long id; @Column(name = "name") private String name; ...

Displaying External JSON API on Ruby on Rails Page

I need help figuring out how to display data from a JSON API on a view page. Currently, I am able to retrieve the data using the code below: require 'json/pure' require 'open-uri' def index content = open("MY_JSON_URL").read ren ...

Iterate through the URL parameters and store them in the database

I need to efficiently loop through all my post requests and aggregate them collectively. What is the most effective approach for achieving this? Below is the Form structure along with the data I receive: var Form = new Schema({ title: { type: ...

Is Next.js compatible with CSS caching?

I'm currently working on a project with Next.js (version 12.1.0) and SCSS modules. I've noticed that my CSS seems to be caching extremely aggressively, requiring me to restart the server (npm run next dev) in order to clear it. Has anyone else en ...

Ensure the legitimacy of data prior to uploading to the server in an Android application

As I work on my android app project, I find myself dealing with sending various data types to a server. My chosen method for file uploads is JSON, but I want to ensure that this process is secure and limited to only authorized devices. Despite using Postma ...

Troubleshooting issues with calculator operators in JavaScript for beginners

As a beginner in JavaScript, I've taken on the challenge of building a calculator to enhance my skills. However, I'm having trouble getting the operator buttons (specifically the plus and equal buttons) to function properly. Can someone please as ...

Scrolling automatically to a DIV is possible with jQuery, however, this feature is functional only on the initial

I'm currently working on a Quiz site and I've encountered a puzzling issue. Since the explanation only appears after an answer is selected - essentially a "hidden" element, I decided to wrap that explanation into a visible DIV. The code I'v ...

Converting JSON Arrays into Typescript Arrays

I am working with a JSON file that contains an array object like this: [ { "VergiNo": "XXXXXXX" }, { "VergiNo": "YYYYYY" }, { "VergiNo": "ZZZZZZ" } ] After importing this JSON file into my Typescript file, import * as companies f ...

Include the component with the function getStaticProps loaded

I am currently working on a project using NextJs and I have created a component to load dynamic data. The component works fine when accessed via localhost:3000/faq, but I encounter an error when trying to import the same component into index.js. It seems l ...

Troublesome problem encountered when sending a JSON object to a C# method, specifically when the method requires a collection as a parameter and is being handled

Encountering a peculiar issue when passing the given data: queueNotificationData = { StartDate: that.batchData.StartDate.valueOf(), StartTime: that.batchData.StartTime.valueOf(), EndDate: that.batchData.EndDate.valueOf( ...

Modify div content based on user selection

I have a question about updating the content of a div based on certain conditions in my code. Here is what I'm trying to achieve: <div class="form-control" ns-show="runningImport" disabled="disabled"> {{input[row.header_safe]}}{{select[row. ...