이 테스트 응용 프로그램이 작동합니다. 그것은 귀하의 json 데이터의 버려진 버전을 사용합니다. 그러나 그것을 동일하게 처리합니다. 나는 또한 다른 JSON 디코더를 사용한다.
내가 생각할 수있는 유일한 점은 createDate 함수에 결함이 있다는 것입니다. 모든 것이 예상대로 작동해야한다는 것을 증명하기 위해 간단한 버전을 사용했습니다.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.charts.DateTimeAxis;
import mx.charts.series.LineSeries;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var frame:ArrayCollection;
protected function creationCompleteHandler(event:FlexEvent):void {
frame = new ArrayCollection();
var data:String = '[{ "content": { "glucose": 135 }, "date_time": "2016,09,15"},' +
'{ "content": { "glucose": 55 }, "date_time": "2016,09,16"},' +
'{ "content": { "glucose": 13 }, "date_time": "2016,09,17"},' +
'{ "content": { "glucose": 70 }, "date_time": "2016,09,18"}]';
var jsonData:Object = JSON.parse(data);
for each (var item:Object in jsonData) {
frame.addItem({ date_time:((item.date_time).toString()) , glucose:(item.content.glucose)});
}
var localSeries:LineSeries = new LineSeries();
localSeries.dataProvider = frame;
localSeries.yField = "glucose";
localSeries.xField = "date_time";
localSeries.displayName = "Glucose Level";
var currentSeries:Array = myChart.series;
currentSeries.push(localSeries);
myChart.series = currentSeries;
var hAxis:DateTimeAxis = new DateTimeAxis();
hAxis.parseFunction = createDate;
myChart.horizontalAxis = hAxis;
}
public function createDate(s:String):Date {
// Get an array of Strings from the
// comma-separated String passed in.
var a:Array = s.split(",");
// Trace out year, month, and day values.
trace("y:" + a[0]);
trace("m:" + a[1]);
trace("d:" + a[2]);
// To create a Date object, you pass "YYYY,MM,DD",
// where MM is zero-based, to the Date() constructor.
var newDate:Date = new Date(a[0],a[1]-1,a[2]);
return newDate;
}
]]>
</fx:Script>
<mx:LineChart id="myChart" />
</s:WindowedApplication>
무엇이 작동하지 않습니까? 해서는 안되는 일이 뭐야? 처음에는 이러한 것을 설명하지 않는 것이 품질이 좋지 않은 것으로 간주됩니다. –
@NealDavis, 답장을 보내 주셔서 감사 드리며 품질이 좋지 않아 사과드립니다. 작동하지 않는 것은 json 배열에서 동적으로 데이터를 얻기 위해 ArrayCollection에서 두 객체 (date_time 및 glucose)를 가져올 수 없다는 것입니다. 데이터가 정적 인 경우에만 작동하지만 json 데이터가 항상 변경되기 때문에 ArrayCollection에 동적으로 입력해야합니다. –
디코딩중인 json 데이터를 게시 할 수 있습니까? –