creating serial bar graph for complex data amcharts

天大地大妈咪最大 提交于 2019-12-12 02:36:01

问题


Below is the response I get as json from server:

[{
  "data1": {
    "name": "Test1",
    "count": 0,
    "amount": 0,
    "amtData": [
      0,0,0,0
    ],
    "cntData": [
      0,0,0,0
    ],
    "color": "#FF0F00"
  },
  "data2": {
    "name": "Test2",
    "count": 1,
    "amount": 4164,
    "amtData": [
      4164,0,0,0
    ],
    "cntData": [
      1,0,0,0
    ],
    "color": "#FF0F00"
  },
  "data3": {
    "name": "Test3",
    "count": 1,
    "amount": 2509,
    "amtData": [
      2509,0,0,0
    ],
    "cntData": [
      1,0,0,0
    ],
    "color": "#FF0F00"
  },
  "data4": {
    "name": "Test4",
    "count": 1,
    "amount": 9909,
    "amtData": [
      9909,0,0,0
    ],
    "cntData": [
      1,0,0,0        
    ],
    "color": "#FF0F00"
  },
  "data5": {
    "name": "Test5",
    "count": 0,
    "dollars": 0,
    "amount": [
      0,0,0,0
    ],
    "cntData": [
      0,0,0,0
    ],
    "color": "#FF0F00"
  }
}]

and here am trying to create my chart.

var chart = AmCharts.makeChart("chartdiv", {
  "theme": "light",
  "type": "serial",
  "dataProvider": data, //assigning it as data
  "startDuration": 1,
  "graphs": [{
    "balloonText": "<b>[[category]]</b><br>starts at [[count]]<br>ends at [[amount]]",
    "colorField": "color",
    "fillAlphas": 0.8,
    "lineAlpha": 0,
    "openField": "count", //base start field
    "type": "column",
    "valueField": "amount" //value field
  }],
  "rotate": true,
  "columnWidth": 0.8,
  "categoryField": "name", //name field
  "categoryAxis": {
    "gridPosition": "start",
    "axisAlpha": 0,
    "gridAlpha": 0,
    "position": "left"
  },
  "export": {
    "enabled": true
  }
});

How much ever I try, I am getting undefined instead of chart.. No console errors either I could make use of. How can I go restructuring this complex data and produce a graph out of it?

Here is the fiddle and this is just sample fiddle which I was referring.


回答1:


You should remove the data1 to data5 properties from your dataProvider:

var data = [
  {
    "name": "Test1",
    "count": 0,
    "amount": 0,
    "amtData": [
      0,
      0,
      0,
      0
    ],
    "cntData": [
      0,
      0,
      0,
      0
    ],
    "color": "#FF0F00"
  },
  ...
];

Look here



来源:https://stackoverflow.com/questions/38350896/creating-serial-bar-graph-for-complex-data-amcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!