views:

33

answers:

2

I am using Flex 4 & zend to create a simple areaseries chart. Currently, I am pulling 20 yrs of data from the database & displaying it by default. I then want to let the user choose the dates he wants, but without going back to the server....how can I do that?
<mx:AreaChart id="Areachart" dataProvider="{employeesResult.lastResult}">

<mx:series>
<mx:AreaSeries yField="numberOfEmployees" xField="date" id="areaSeries"/> </mx:series>
</mx:AreaChart>

<mx:LinkButton click="dateChange()" label="1 year" />

private function dateChange():void{
what goes here????
}

A: 

add another one array and fill it like this:

for(startDate;less then endDate;iterate) { fill with data from employeesResult.lastResult }

or explain what do you want in details?

Eugene
I've tried this: `private function dateChange():void{areaSeries.dataProvider = employeesResult.lastResult.slice(-365);}` that should give me the last 365 items, right? (ie the most recent year's worth of data. (But it doesn't work...nothing shows in the chart) I got it from here:`http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/Array.html`
ginius
test something like this: *areaSeries.dataProvider = employeesResult.lastResult.slice(0,100);* and you cannot use start index less the zero, check back your link. Also you could try myChart.invalidateDisplayList(); after changing DataProvider
Eugene
thanks. That still doesn't work. employees.lastResult(0,100) returns an empty array.
ginius
it seems like this should be something pretty simple to implement, right? For some reason, none of these methods work
ginius
okay, then give me your runnable sample with embedded data and no external service so we could do something next.
Eugene
hmmm....I don't know how much better I can explain it. I am a weekend hacker, so all this is very new to me. I basically followed this: http://www.flepstudio.org/forum/flex-builder-3-eng/6089-connecting-flex-4-zend-using-flash-builder-4-a.html Now, I am trying to manipulate the data that is retrieved from the php.....quick note, when I put in "employeesResult.lastResult." it doesn't give me code hinting so I think putting the "slice" there is the wrong way to do it, I think.
ginius
could you determine the type of dataprovider?
Eugene
I've now added a filter function, as suggested above, but no luck.` public function filterByRange( item:Object ):Boolean { return true; } <s:ArrayCollection id="dg" filterFunction="filterByRange" /> <s:CallResponder id="getDataResult"/> <datadata:DataData id="dataData" /><mx:AreaChart id="areachart1" creationComplete="getData(event)" dataProvider="{dg}" showDataTips="true"> <mx:series> <mx:AreaSeries yField="price" id="areaSeries" xField="date"/> </mx:series> <mx:horizontalAxis> <mx:DateTimeAxis/> </mx:horizontalAxis> </mx:AreaChart></s:Application>`
ginius
and the php code:public function get() {$stmt = mysqli_prepare($this->connection, "SELECT * FROM table"); $this->throwExceptionOnError(); mysqli_stmt_execute($stmt);$this->throwExceptionOnError(); $rows = array(); mysqli_stmt_bind_result($stmt, $row->date, $row->price); while (mysqli_stmt_fetch($stmt)) { $row->date = new DateTime($row->date); $rows[] = $row; $row = new stdClass(); mysqli_stmt_bind_result($stmt, $row->date, $row->price); } mysqli_stmt_free_result($stmt);mysqli_close($this->connection); return $rows; }
ginius
A: 

rather than sticking the result of the service call straight into the graph. Keep it on a model somewhere.

If you add it into an ArrayCollection (or really anything that implements ICollectionView) you can then use the filter functions exposed by that to filter your dataset before it's fed into the graph.

You also get the advantage of being able to re-filter the results. By slicing up the array, you are altering your base data set.

Gregor Kiddie
ginius
http://tinyurl.com/384eaye
Gregor Kiddie
ginius
something like...<mx:ArrayCollection id="dp" source="{employeesResult.lastResult}" filterFunction="myFilterFunction" /><mx:AreaChart id="Areachart" dataProvider="{dp}">
Gregor Kiddie