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

Changing the decimal point display in AngularJS

When a user enters a number with more than two decimal places in any of the 10 textboxes, I want it to automatically round down to two decimal places. <input ng-model='data.value1' ng-blur="formatDecimals1()"> <input ng-model='data ...

Tips on retrieving the URL of a background image using "$event.target" to display in an Ionic modal

How can I display the clicked image in a modal? Implementation: <a ng-click="openModal($event)" ng-style="{'background-image': 'url(assets/img/img-01.jpg)'}"><img src="assets/alpha-4x3.png"></a> <a ng-click="openM ...

Creating dynamic forms with JQuery and ReactJS

I have been tasked with creating a form-builder that will be integrated into an application. My role is to focus on designing the front-end using ReactJS. The client’s requirements are very similar to the features of the "jQuery Form-Builder," so I decid ...

Steps to clear a form after submitting it

Hello all, I have a rather complex form that sends a message successfully with an alert after submission. I'm wondering how I can clear the entire form once it has been submitted to make it simple? Below is my HTML Form and JavaScript code. I would l ...

Is it possible to check dynamically if a string contains multiple substring matches?

Currently, I am in the process of developing a search suggest feature that will provide the best match based on certain criteria. Below is the code snippet along with my explanatory comments. /* string = {"Canna Terra PLUS 50 Litres", "Canna Vega ...

Learn the process of zipping a folder in a Node.js application and initiating the download of the zip file afterwards

After encountering issues with the latest version of the npm package adm-zip 0.4.7, I reverted to an older version, adm-zip 0.4.4. However, despite working on Windows, this version does not function correctly on Mac and Linux operating systems. Additionall ...

After props have been passed, the ReactJS ComponentWillMount() function is triggered

Can anyone explain why the child component is only rendered once, even though I pass props to it every time I click a button? Whenever I click a button that passes props to the child, the ComponentWillMount() method of the child component doesn't tri ...

What is the process for loading a .x model in Three.js?

Could anyone provide guidance on how to successfully load an animated .x model in Three.js? I am currently struggling with the process and have attempted to convert the .x model to collada without success. Unfortunately, my search for a free program to c ...

Utilizing JavaScript and its scope to include text within an HTML document

I am currently working on a program that receives input from the user twice, specifically a risk carrier and a sum (although it is just a placeholder for now), groups these two values together, and then repeats the contents in a loop. You can see the progr ...

How can I refresh a page in Ionic 2?

When refreshing an Ionic2 Page using the location.reload() method, there is a 4-5 second delay on Android devices where a blank white page appears before the reload happens. How can I fix this issue? Any suggestions on how to resolve it would be greatly ...

JS seems to kick in only after a couple of page refreshes

I'm facing an issue with my 3 columns that should have equal heights. I've implemented some JavaScript to achieve this, which you can see in action through the DEMO link below. <script> $(document).foundation(); </script> <scri ...

Issue with Chrome not triggering onMouseEnter event when an element blocking the cursor disappears in React

Important Note: This issue seems to be specific to Chrome Currently, React does not trigger the onMouseEnter event when a blocking element disappears. This behavior is different from standard JavaScript events and even delegated events. Below is a simpli ...

Utilizing Next 13 for flexible MDX imports

Recently completed the Next13 + MDX Tutorial, however, I am still unclear on how to dynamically load my mdx files. My mdx files are not hosted on a remote server, so I do not require next-mdx-remote. Nonetheless, I am in need of a method to load different ...

Ensure that the promise is fulfilled only if a specific condition is met

I have a complex if-else condition in my code that includes different promises. Once the logic determines which condition to enter and executes the corresponding promise, I need to ensure that a final promise is always executed. if (a < 5) { vm.pr ...

How can I effectively assign model data to a service property in an AngularJS controller?

I have established a service to facilitate the sharing of data/state across multiple controllers. One of the controllers updates certain properties within the service using scope data through a save function. The updated data is then accessed by other cont ...

Performance comparison between Javascript Object and Map/Set for key lookup

I decided to experiment with the performance of JavaScript Object, Map, and Set when it comes to accessing keys. I tested the following three code snippets on JSBEN.CH. Objects const object = {}; for (let i = 0; i < 10000; ++i) { object[`key_${i}` ...

Attempting to serialize a form using Ajax and jQuery

I am facing an issue with submitting user input from a modal using jQuery and AJAX. The problem is that the AJAX call is not capturing the user input. Even though the AJAX call is successful, when I check on the server side, the user input appears to be bl ...

Using Timing Function to Dynamically Add Multiple Markers from JSON

Despite reading all related articles about my question, I still don't have a complete answer... I could really use some help with this app idea! My App: Adding multiple markers with a timer from a JSON file that has been parsed from a MySQL database: ...

Utilizing JSON data for Autocomplete with Ajax and Jquery

I have been working on setting up my Jquery UI autocomplete field to pull data from an ajax connection. Here is the progress I've made so far: $("#mainIngredientAutoComplete").autocomplete({ source: function (request, response) { $.ajax({ ...

Internet Explorer (on mobile devices) does not display submenus when touched

Hello, I have a query about displaying a sublist on touch. I have created a sublist that is supposed to show up when you hover over it. You can view the demo here: @import url(//fonts.googleapis.com/css?family=Titillium+Web:400,200,300,600,700); body { ...