The Echart bar graph is not displaying when trying to use JSON data

Seeking assistance as a beginner in building Basic Bar inverted axes using json data. I am trying to achieve a chart similar to Bar Inverted Axes, but encountering issues with the chart not displaying properly. Utilizing Angular to develop the web application, here is my controller:

.controller("JsonCtrl", function ($scope, $http,$location, chartBar) {
       
        $scope.data1 = {};

        $http.get('data/set.json')
            .success(function (data1) {
                 var axis1 = [],seriesa = [],seriesb = [], seriesc = [], seriesd = [], seriese = [] ;
                  data1.forEach(function(row) {
                    axis1.push(row.data1);
                    seriesa.push(row.data2);
                    seriesb.push(row.data3);
                    seriesc.push(row.data4);
                    seriesd.push(row.data5);
                    seriese.push(row.data6);
                   
                    });
   
                $scope.data1.a=axis1;
                $scope.data1.b=seriesa;
                $scope.data1.c=seriesb;
                $scope.data1.d=seriesc;
                $scope.data1.e=seriesd;
                $scope.data1.f=seriese;
             

              /**/
                console.log($scope.data1);

               
                var c = chartBar('mainb',$scope.data1);
                               //windows responsive
                window.onresize=function ()
                 {
                    c.resize()
                    
                }
                //
            })  
            .error(function (error) {
                $scope.data.error = error;
            });

    })

The JSON data used for this operation includes:

{
  "data1": ["Smtra", "Jawa", "Klmtn", "Sulwsi", "Maluku"],
  "data2": [149739, 244347, 54462, 59869, 6713],
  "data3": [150089, 223519, 49523, 58881, 6152],
  "data4": [141625, 200745, 46966, 54637, 6733],
  "data5": [120428, 173979, 42208, 45067, 6034],
  "data6": [114254, 164168, 39415, 38750, 5301]
}

Furthermore, there is a factory designed to facilitate chart creation:

.factory('chartBar',function(echartTheme){
        return function(element, data1){
            var echartBar = echarts.init(document.getElementById(element), echartTheme);

            echartBar.setOption({
                title: {
                    text: 'Bar Graph',
                    subtext: 'Bar'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    x: 100,
                    data: ['2010', '2011', '2012', '2013', '2014']
                },
                toolbox: {
                    show: true,
                    feature: {
                        saveAsImage: {
                            show: true,
                            title: "Save Image"
                        }
                    }
                },
                calculable: true,
                xAxis: [{
                    type: 'value',
                    boundaryGap: [0, 0.01]
                }],
                yAxis: [{
                    type: 'category',
                    data: data1.a
                }],
                series: [{
                    name: '2010',
                    type: 'bar',
                    data: data1.b
                }, {
                    name: '2011',
                    type: 'bar',
                    data: data1.c
                }, {
                    name: '2012',
                    type: 'bar',
                    data: data1.d
                }, {
                    name: '2013',
                    type: 'bar',
                    data: data1.e
                }, {
                    name: '2014',
                    type: 'bar',
                    data: data1.f
                }]
            });
        }
    })

Your help would be greatly appreciated :)

Answer №1

In order for ECharts to refresh its data, you must execute the echartBar.setOption method.

To achieve this, try implementing the following:

echartBar.setOption({
    series: [{
        data: $scope.data1
    }]
});

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

How can I only replace every second occurrence in a JS string?

Looking for help with JavaScript: "a a a a".replace(/(^|\s)a(\s|$)/g, '$1') I thought the result would be '', but it's showing 'a a' instead. Can someone explain what I'm missing? To clarify, I want to r ...

How to retrieve the same value from multiple selections using Vanilla JavaScript and multiple select options?

Why do we consistently receive the same value and index when using the ctl key to select multiple options? document.querySelector('select').addEventListener('change', function(e) { console.log(this.selectedIndex) console.log(e.ta ...

Troubleshooting issues with jQuery `.live()` event not triggering as expected

In a project I am working on, I have implemented complex AJAX functionality to fetch inner page content from a WordPress blog. Due to the dynamic nature of the site, where the DOM is replaced after page load via AJAX, I have opted to use jQuery's .liv ...

Ways to verify the identity of a user using an external authentication service

One of my microservices deals with user login and registration. Upon making a request to localhost:8080 with the body { "username": "test", "password":"test"}, I receive an authentication token like this: { "tok ...

Remove user from firebase with Admin SDK

I need help understanding how to remove a user from my admin panel using the Firebase Admin SDK. When attempting to delete a user, I encountered this error: Uncaught (in promise) ReferenceError: uid is not defined at eval (ManageCustomer. ...

What is the best way to implement a fade animation with nganimate when transitioning between routes in Angular ui-router?

.ng-leave { transition: 1s linear all; opacity: 1; } .ng-leave-active { opacity: 0; } The code above specifies a fade animation whenever the router changes routes from one page (page1.html) to another (page2.html). However, if you want to hav ...

Typescript: defining an interface that inherits properties from a JSON type

When working with TypeScript, I've utilized a generic JSON type as suggested in this source: type JSONValue = | string | number | boolean | null | JSONValue[] | {[key: string]: JSONValue} My goal is to cast interface types matching JSON to and ...

Tips for subscribing to an Angular Unit Test:

In the process of writing test cases for a component, I first tackled a basic test case to ensure smooth functionality. Initially, I faced Dependency Injection errors and managed to resolve them. The current challenge I am encountering involves mocking API ...

Issue: The function (0, react__WEBPACK_IMPORTED_MODULE_1__.useActionState) is not recognized as a valid function or its output is not iterable

I found a great example of using useActionState at this source. Currently, I am implementing it in my project with Next.js and TypeScript. app/page.tsx: "use client"; import { useActionState } from "react"; import { createUser } from ...

How can you modify the starting point of data in jQuery flot?

Currently using Flot to create a graph displaying clicks per minute within the first 60 minutes of short URLs generated at . The graph currently displays data from minute 0 to minute 59. My query is about adjusting the data to start at 1 and end at 59, wh ...

Tips for getting the sum of an array using the reduce method in Vue.js and returning the result array

As someone new to JavaScript, I apologize if my description of the issue is not clear. It's challenging for me to explain the problem I am facing. I have a computed function where I use the reduce method to iterate over my objects, perform calculatio ...

performing a query on two tables with sequelize

There must be a more efficient way to accomplish this task with fewer lines of code. I am not very experienced with databases and I am new to sequelize and node. The user id is passed as a parameter and I need to check if there is a corresponding user in ...

Align list items in the center horizontally regardless of the width

I have created this container element: export const Container = styled.section<ContainerProps>` display: flex; justify-content: center; `; The current setup is vertically centering three list items within the container. However, I am now looking ...

What is the best way to download a file with a specific name using Angular and TypeScript?

Greetings! Below is a snippet of code from my Angular component: this.messageHistoryService.getMessageHistoriesCSV1(msgHistoryRequest).subscribe( (data) => { console.log(data.messageHistoryBytes); let file = new Blob( [data.messageHistoryBytes ...

iOS6: Using POST method to send JSON data from an iPhone to a REST API

I have encountered an issue while trying to send data in JSON format to a REST API. The web service does not return any data when sending a parameter and instead shows the error message: Error parsing JSON: Error Domain=NSCocoaErrorDomain Code=3840 "The op ...

Using Node.js and the Azure DevOps Node API, you can easily retrieve attachments from Azure DevOps work items

Encountering a problem while attempting to download an attachment for a work item in Azure DevOps. Utilizing the node.js 'azure-devops-node-api' client (https://www.npmjs.com/package/azure-devops-node-api) to communicate with ADO API. Retrieving ...

What causes the Element to be null in Vue.js?

Could someone please clarify why the console.log output is showing as null, and provide guidance on how to resolve this issue? <template v-for="day in getMonthLength()"> <td> <input :id="day" type=number :value=&qu ...

Contrasting the use of jQuery versus AJAX for updating static page text

While I haven't fully grasped the concept of AJAX yet, my understanding is that it can be beneficial for updating specific parts of a webpage. Does using AJAX only make sense when you require server interaction? I am looking to replace text on a webp ...

Converting a string to HTML in Angular 2 with proper formatting

I'm facing a challenge that I have no clue how to tackle. My goal is to create an object similar to this: { text: "hello {param1}", param1: { text:"world", class: "bla" } } The tricky part is that I want to ...

Intermittent loading issues with Highcharts using AJAX requests

We've encountered intermittent errors when using Highcharts. Despite our efforts, we can't seem to pinpoint the cause of these issues in Chrome: Uncaught Highcharts error #16: www.highcharts.com/errors/16 VM210:16 HighCharts was already loaded V ...