1

当我们创建弹性图表时,例如柱形图,我们必须绑定一个 ArrayCollection,如下所示:

[Bindable]
private var chartData:ArrayCollection = new ArrayCollection([
    {X: "Jan", Y: 10},
    {X: "Feb", Y: 20},
    {X: "Mar", Y: 30}
]);

如果我需要从 Java 后端获取这些数据,那么在 java 中可以使用什么样的数据结构?

谢谢!

4

1 回答 1

1

尝试这个

// this class is used for the arraylist/collection of point X and Y
// on actionscript side you will see the property you declare as public 
public class ChartPoint {
    public String X;
    public String Y;      
}



public class ChartData{          
 // method called from remoteobject from actionscript
 // it will return a java arraylist of type chartpoint
 // actionscript will receive an arraycollection with the property of 
 // ChartPoint you declared public
  public ArrayList<ChartPoint> getValuesFromChart()
  { 
   ArrayList<ChartPoint> chartData = new ArrayList<ChartPoint>();
   ....
   // initialization and fill the chartData list...
   return chartData;
  }
}

在 actionscript 中,您将使用 AMF 协议...

ro = new RemoteObject();
ro.destination = "destination"; // configured in blazeds/tomcat server
var cs:ChannelSet = new ChannelSet();
var customChannel:Channel = new AMFChannel("my-amf", "http://your-amf-channel");
cs.addChannel(customChannel);
ro.channelSet = cs;             
ro.addEventListener(ResultEvent.RESULT,
    function(e:ResultEvent):void{       
        if (e.result != null)
        {                       
            // you have a result...
                   this.chartData = e.result;
        }               
    });         
ro.addEventListener(FaultEvent.FAULT,function(e:FaultEvent):void{ 
 // manage the error
});         

ro.getValuesFromChart();
于 2012-04-30T12:37:26.157 回答