flex:正确显示自定义dataTipRenderer的问题

时间:2011-08-09 10:10:40

标签: flex charts

我有一个带有自定义dataTipRenderer的flex AreaChart:

<mx:AreaChart id="numParticipants" 
                  dataProvider="{UsersModel.graphData.data_points.point}" 
                  seriesFilters="[]" right="10" left="10" 
                  top="10" bottom="10" fontSize="9" color="#8D8D8D"
                  dataTipRenderer="tooltip.ChartTooltip"
                  showDataTips="true" dataTipMode="multiple" mouseSensitivity="10">

渲染器代码在这里:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" top="5" width="154" height="42">

    <mx:Style source="css/style.css"/>
    <mx:Script>
        <![CDATA[
            import models.UsersModel;
                import mx.charts.HitData;           
            import mx.formatters.DateFormatter;

            override public function set data(value:Object):void
            {
                //trace("ChartTooltip: x=" + x + " y=" + y);
                    var dataPoint:HitData = value as HitData;
                    var date:Date = new Date();
                var units:String = UsersModel.graphData.units;

                    date.setTime(dataPoint.item.timestamp * 1000);

                switch (units)
                {
                    case "days":
                        txtDate.text = dayFormatter.format(date);
                    break;
                case "hours":
                    txtDate.text = hourFormatter.format(date);
                    break;
            }
            txtUsers.text = dataPoint.item.participants;
        }
    ]]>
</mx:Script>

<mx:DateFormatter id="hourFormatter" formatString="L:NN A"/>
<mx:DateFormatter id="dayFormatter" formatString="MMM DD"/>
<mx:Image source="@Embed('images/BaloonLeft.png')" x="0" width="25" height="42" y="0" maintainAspectRatio="false" />
<mx:Image source="@Embed('images/BaloonCenter.png')" x="25" width="120" height="42" y="0" maintainAspectRatio="false"/>
<mx:Image source="@Embed('images/BaloonRight.png')" x="145" width="9" height="42" y="0" maintainAspectRatio="false" />
<mx:VBox x="25" width="120" height="42" y="0" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalGap="0">
    <mx:HBox>
        <mx:Label text="Date:" styleName="dataTooltipText" fontWeight="bold"/>
        <mx:Label id="txtDate" styleName="dataTooltipText"/>
    </mx:HBox>
    <mx:HBox>
        <mx:Label text="Users:" styleName="dataTooltipText" fontWeight="bold"/>
        <mx:Label id="txtUsers" styleName="dataTooltipText"/>
    </mx:HBox>
</mx:VBox>

工具提示正确显示某些数据点,但对于其他数据点,它看起来不太好。

以下是屏幕截图:

http://www.flickr.com/photos/91145267@N00/6025401750/in/photostream

任何想法为什么?

非常感谢!

奥弗

1 个答案:

答案 0 :(得分:0)

我建议将图片和内容放在自定义layoutContainer中,例如HBox:

<mx:HBox>
    <mx:Image source="@Embed('images/BaloonLeft.png')" x="0" width="25" height="42" y="0" maintainAspectRatio="false" />
    <mx:Canvas>
        <mx:Image source="@Embed('images/BaloonCenter.png')" x="25" width="120" height="42" y="0" maintainAspectRatio="false"/>

        <mx:VBox x="25" width="120" height="42" y="0" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalGap="0">
            <mx:HBox>
                <mx:Label text="Date:" styleName="dataTooltipText" fontWeight="bold"/>
                <mx:Label id="txtDate" styleName="dataTooltipText"/>
            </mx:HBox>
            <mx:HBox>
                <mx:Label text="Users:" styleName="dataTooltipText" fontWeight="bold"/>
                <mx:Label id="txtUsers" styleName="dataTooltipText"/>
            </mx:HBox>
        </mx:VBox>
    </mx:Canvas>
    <mx:Image source="@Embed('images/BaloonRight.png')" x="145" width="9" height="42" y="0" maintainAspectRatio="false" />
</mx:HBox>

我还没有真正测试过这个,但我想给你一个主要的想法。 HBox水平布局所有内容,我介绍的Canvas可以将背景和内容相互绘制。正如我所提到的......我希望它能给你一般的想法。

克里斯