开发者

Flex Chart won't filter

I have flex 4, zend & php. I am trying to generate a chart w/ 5 yrs of data & then let the user (without making another call to the server) get a 1 yr chart w/ the same data. (In other words, the 1 yr's worth of data is a subset of the 5 yrs). I can get the initial 5 yr chart but when I try to apply a filter, as below, I get no data. What am I doing wrong?

I have the following code:

`

 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           xmlns:datadata="services.datadata.*">
<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.FlexEvent;

        protected function getData(event:FlexEvent):void
        {                               
            getDataResult.token = dataData.getData();

        }

        public function filterByRange(item:Object):Boolean 
        {
            var result:Boolean = true;

            if (item.date.time > 2007-01-01 && item.date.time < 2008-12-31 ){
                result = false;
            }
            return result;
            dg.refresh();
        }

    ]]>
</fx:Script>
<fx:Declarations>
    <s:ArrayCollection id="dg" filterFunction="filterByRange" list="{getDataResult.lastResult}"  />
    <s:CallResponder id="getDataResult"/>
    <data开发者_运维百科data:DataData id="dataData" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
</fx:Declarations>



<mx:AreaChart id="areachart1" width="100%" height="100%" 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>

`

This is what my PHP code looks like. Remember, I am using Zend.

`

           public function getData() {

    $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");        
    $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;
}

`


For your date range case, you can try something like:

private var startDate:Date = new Date(0); // epoch
private var endDate:Date = new Date(); // now

public function filterByRange(item:Object):Boolean 
{
    var itemDate:Date = item.date;
    return (itemDate.time > startDate.time) && (itemDate.time < endDate.time);
}

private function onClick():void
{
    startDate = new Date("2007/01/01");
    endDate = new Date("2008/12/31");
    dg.refresh();
}

...

<s:Button click="onClick()"/>

You'll need to make sure to call refresh on your ArrayCollection to apply the filter again. Just threw in a button click action for an example user interaction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜