2016-08-30 3 views
1
내 AngularJS와 응용 프로그램에 AmCharts을 사용하고

을 중첩 된 JSON 데이터에 액세스하고 내가 돌아올 어떤이는 JSON 데이터입니다 방법 :AmCharts

{ 
total: 2, 
tools: [ 
{ 
id: "57c5a75d57d92f742dc96bf2", 
empId: "1", 
empName: "ABC", 
empType: { 
typeId: 3, 
typeName: "Contract", 
hours: 45, 
} 
}, 
{ 
id: "57c5a75d57d92f742dc96bf2", 
empId: "2", 
empName: "DEF", 
empType: { 
typeId: 2, 
typeName: "Full-Time", 
hours: 40, 
} 
}, 


] 
} 

코드를 내 컨트롤러 :

const writeemp = data => { 
     const { 
      total, 
      employees, 
     } = data; 

     empChart.dataProvider = employees; 
     empChart.write('emp'); 
     empChart.validateData(); 
    }; 

    AmCharts.handleLoad(); 

    var configChart = function() { 


     empChart = new AmCharts.AmSerialChart(); 
     empChart.categoryField = "empId"; 
     empChart.labelRotation = 90; 

     var yAxis = new AmCharts.ValueAxis(); 
     yAxis.position = "left"; 
     empChart.addValueAxis(yAxis); 


     empBarGraph = new AmCharts.AmGraph(); 
     empBarGraph.valueField = "";//This to be the value "TypeName" in "empType" from the Json Data 
     empBarGraph.type = "column"; 
     empBarGraph.fillAlphas = 1; 
     empBarGraph.lineColor = "#f0ab00"; 
     empBarGraph.valueAxis = yAxis; 
     empChart.addGraph(empBarGraph); 
     empChart.write('empChart'); 


     $http.get(hostNameService.getHostName()+"/dashboard/employees") 
      .then(response => writeemp(response.data)); 
    } 

수 누군가는 Amcharts에서 중첩 된 Json 데이터에 어떻게 액세스 할 수 있는지 알려주었습니다. 필자는 필드 중 하나를 차트의 valueField로 사용하려고합니다.

답변

1

AmCharts는 중첩 된 JSON 세트를 지원하지 않습니다. valueField() 및 categoryField가 포함 된 객체의 병합 된 배열로 데이터를 재구성해야합니다. 귀하의 경우 : 그래프는 값 축에 대한 숫자 값을 지원할 수

[ 
    { 
    "empId": 1, 
    "typeName": "Contract" 
    }, 
// ... 
] 

주, 그래서 "유형 이름"적절한 valueField하지 않습니다.

+0

도움 주셔서 감사합니다. 이 경우 사용자 지정 데이터 구조를 만들었습니다. 그래, 우리는 차트의 값 필드로만 숫자를 사용할 수 있다는 것을 알고 있습니다. – Valla