3 Replies Latest reply on Mar 18, 2009 6:42 AM by Cr99

    Open ended data structure for retrieving SQL data

    Cr99 Level 1
      I have a flex project that reads data from a database and sends it to my flex app to display in a chart. I need to do this in Actionscript since I have to dynamically create different charts based on the database definitions. Up til now, I have inserted the data for each series into a separate ArrayList(java)/ArrayCollection(flex) in this way:

      BindingUtils.bindProperty(lineSeries, "dataProvider", series, "pointList");
      lineSeries.xField="point1";
      lineSeries.yField="point2";

      The series variable is a custom Actionscript/Java object which contains an ArrayCollection called pointList. And the array is made up of custom DataObjects with two fields, point1 & point2.

      But in the new paradigm, I'd basically like to create a big array of arrays similar to a database table and then just point the xField to one column, and the yField to another column. Anyway, it seems like the problem is that my point1 and point2 in the current implementation are variable names, but with this new dynamic structure, I won't be able to create variables on the fly. So how do I let flex know to look at column 3, for example for the yField? The attached code is from the Flex documentation and is an example of what I'd like to emulate (except I need to do it in actionscript). I'd like to be able to select "month" or "amount", etc. But coming from the Java side, there is no way for me to name the array contained in each column.

        • 1. Open ended data structure for retrieving SQL data
          Cr99 Level 1
          Ok, maybe that post was too hard to understand. Let me boil it down to this, how can I create this data structure in a Java class that will map to a flex class:

          public var expenses:ArrayCollection = new ArrayCollection([
          {Month:"Jan", Profit:2000, Expenses:1500},
          {Month:"Feb", Profit:1000, Expenses:200},
          {Month:"Mar", Profit:1500, Expenses:500}
          ]);

          Keep in mind, I won't know at runtime if there are 3 fields to each item (like the example shown) or if there are 100 fields. It will just depend on the data I need to chart.

          For that matter, how would you even create such an ArrayCollection in Actionscript like this one if you didn't know the number of fields at runtime?
          • 2. Re: Open ended data structure for retrieving SQL data
            Gregory Lafrance Level 6
            This FB3 help sys page describes Java to AS types.

            Using RemoteObject components
            • 3. Open ended data structure for retrieving SQL data
              Cr99 Level 1
              I guess I wasn't clear enough. I am actually serializing a java object and mapping it to an actionscript object via blazeDS. I know about how the objects translate, for example for ArrayCollections in flex, I use ArrayLists in java. The problem is that I'm not sure how to get the associative aspects of the arrays in flex into my java data structures in a way that will translate to the way flex can define arrays, such as Month:"January".

              It seems that in flex, you can create an Array and assign it an element like {month:"January", amount:"450"} and it will create an Object with variables for month and amount. But I don't know how to do this on the fly in Java (or in Actionscript for that matter) when I have no way of knowing beforehand how many variables my object will need. Each series will need an x and y, though usually the x will be dates which are the same for each series. So if I had 10 series sharing an axis, I'd need 11 variables in my object- date, series1, series 2...series 10.