0
votes

I am trying to access an object as DataProvider for amcharts by using DataLoader Plugin but it will not show. Here is my JSON Output:

{
    "ReportName":"This is the Report Name",
    "Column-1":"This is the Report Name",
    "Column-2":"This is the Report Name",
    "Data":[
      {"Category":"Guntur","Column_1":"20.30","Column_2":"22.34"},
      {"Category":"Chittor","Column_1":"20.30","Column_2":"22.34"}
    ]} 

This is my script for Amchart:

AmCharts.makeChart("chartdiv",
            {
                "type": "serial",
                "categoryField": "Category",
                "columnWidth": 0.72,
                "angle": 15,
                "depth3D": 10,
                "plotAreaFillAlphas": 0.01,
                "startDuration": 1,
                "fontFamily": "Lato",
                "dataLoader": {
                    "url": "chartInformation",
                    "format": "json"
                  },
                "export": {
                    "enabled": true
                },
                "categoryAxis": {
                    "autoRotateAngle": 0,
                    "gridPosition": "start",
                    "boldLabels": true,
                    "labelRotation": 25.2
                },
                "chartScrollbar": {
                    "enabled": true
                },
                "trendLines": [],
                "graphs": [
                    {
                        "balloonText": "[[category]]  <br> [[title]]  :  [[value]]",
                        "fillAlphas": 1,
                        "id": "AmGraph-1",
                        "title": "Target",
                        "type": "column",
                        "valueField": "Column_1"
                    },
                    {
                        "balloonText": "[[category]]  <br> [[title]]  :  [[value]]",
                        "fillAlphas": 1,
                        "id": "AmGraph-2",
                        "title": "Achieved",
                        "type": "column",
                        "valueField": "Column_2"
                    }
                ],
                "guides": [],
                "valueAxes": [
                    {
                        "id": "ValueAxis-1",
                        "title": "Cost in Lakhs"
                    }
                ],
                "allLabels": [],
                "balloon": {
                    "horizontalPadding": 12
                },
                "legend": {
                    "enabled": true,
                    "backgroundAlpha": 0.01,
                    "rollOverGraphAlpha": 0,
                    "useGraphSettings": true
                },
                "titles": [
                    {
                        "id": "Title-1",
                        "size": 15,
                        "text": "Opening of PMJDY Accounts"
                    }
                ]
            }
        );

In the url tag I'm giving the url for retrieving the json output. How can I use Data Object for chart Data?

Other data of json will be must because I want to use other Data of ReportName.

1
what is "chartInformation" ? is it your url path ?Sagar R
yes.the output of the url is JSON String .i showed in the topKalishavali Shaik
Than you should write like this "data": "chartInformation", instead of "url": "chartInformation",Sagar R
Actually from that url: localhost:8080/Project/cahrtInformationKalishavali Shaik
i got the output i displayed in top in that please check once data object is there that i want to use for the data......Kalishavali Shaik

1 Answers

0
votes

you need to code a dataLoader postProcess that reads in your json data, writes back the data part, and does something useful with the report name , column 1 and 2 values if you wish, such as setting the report title values. see https://www.amcharts.com/tutorials/using-data-loader-plugin/

e.g.

"dataLoader": {
                    "url": "chartInformation",
                    "format": "json"
                     postProcess: function(data, options) {
                         // your code goes here to produce correct data etc
                         return data;
                     }
                  },