Apache flex 在Flex条形图中显示y轴以外的图像/图标

Apache flex 在Flex条形图中显示y轴以外的图像/图标,apache-flex,charts,categories,customization,Apache Flex,Charts,Categories,Customization,我试图在y轴上放置标签旁边的图像。因此,我创建了一个自定义标签渲染器(一个包含和的HBox)。必须根据数据提供程序中存在的属性设置图像的源。问题是,我无法访问fnSetSource()方法中的BarSeriesItem。非常感谢您的帮助或指点。 这是全部代码 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="1280" height="75

我试图在y轴上放置标签旁边的图像。因此,我创建了一个自定义标签渲染器(一个包含和的HBox)。必须根据数据提供程序中存在的属性设置图像的源。问题是,我无法访问fnSetSource()方法中的BarSeriesItem。非常感谢您的帮助或指点。 这是全部代码

 <mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        width="1280" height="750">  
  <mx:Script><![CDATA[
    import mx.collections.ArrayCollection;
    import mx.charts.series.items.PlotSeriesItem;
    import mx.controls.Label;
    import mx.controls.Image;
    import mx.containers.HBox;
    import mx.charts.series.items.BarSeriesItem;
    import mx.charts.series.ColumnSeries;
    import mx.charts.series.items.ColumnSeriesItem;
    import mx.charts.chartClasses.Series;
    import mx.charts.ChartItem;
    [Bindable]
public var employeedetails:ArrayCollection = new ArrayCollection([              
{rank:"10",emplName:"Peter",prevRank:"7",imgSource:"images/increase.png"},
{rank:"9",emplName:"Mark",prevRank:"3",imgSource:"images/decrease.png"},
{rank:"8",emplName:"Eric",prevRank:"8",imgSource:"images/decrease.png"}


]);
    ]]>
    </mx:Script>    


    <mx:BarChart id="bar" height="100%"  
            paddingLeft="15" paddingRight="5" 
            showDataTips="true"  width="847" 
            dataTipMode="multiple" >
            <mx:verticalAxis>
                <mx:CategoryAxis id="v1" categoryField="emplName" dataProvider="{employeedetails}"/>
            </mx:verticalAxis>

            <mx:verticalAxisRenderers>
                <mx:AxisRenderer placement="left" axis="{v1}">
                    <mx:labelRenderer>
                        <mx:Component>
                            <mx:HBox width="100%" height="100%" minWidth="120" minHeight="20">
                                <mx:Image id="axisImage" height="16" width="16" source="fnSetSource()">
                                    <mx:Script><![CDATA[
                                        import mx.charts.chartClasses.Series;
                                        import mx.charts.ChartItem;
                                        import mx.charts.series.items.BarSeriesItem;                                        
                                        [Bindable]
                                        public function fnSetSource(element : ChartItem, series : Series) : String
                                        {
                                        var data : BarSeriesItem = BarSeriesItem(element);
                                        var imgSrc : String = "";
                                        if (data.item.isIncrease)
                                        {
                                        imgSrc = "images/increase.png";
                                        } else if (data.item.isDecrease)
                                        {
                                        imgSrc = "images/decrease.png";
                                        }
                                        else
                                        {
                                        imgSrc = "";
                                        }
                                        return imgSrc;
                                        }
                                    ]]></mx:Script>
                                </mx:Image>
                                <mx:Label id="axisLabel" fontSize="12" width="100%" height="100%">
                                    <mx:Script><![CDATA[
                                        [Bindable]
                                        override public function set data(value : Object) : void
                                            {
                                            if (value == null)
                                            {
                                                return;
                                            }
                                            var length : int = value.text.toString().length;
                                            if (length > 15)
                                            {
                                                axisLabel.text = value.text.toString().substr(0, 15) + "...";
                                                axisLabel.toolTip = value.text;
                                            }
                                            else
                                            {
                                                axisLabel.text = value.text;
                                            }
                                        }
                                    ]]>
                                    </mx:Script>
                                </mx:Label>
                            </mx:HBox>
                        </mx:Component>
                    </mx:labelRenderer>
                </mx:AxisRenderer>
            </mx:verticalAxisRenderers>
            <mx:series>
                <mx:BarSeries id="bs2"
                yField="emplName" 
                xField="rank" 
                displayName="Rank"    
                dataProvider="{employeedetails}"                                 
                />          
        </mx:series>
    </mx:BarChart>
</mx:Application>

15)
{
axisLabel.text=value.text.toString().substr(0,15)+“…”;
axisLabel.toolTip=value.text;
}
其他的
{
axisLabel.text=value.text;
}
}
]]>

我快速查看了代码。fnSetSource()函数只有放在花括号内才会被调用:source=“{fnSetSource()}”

这将获得要调用的函数,但会出现错误,因为fnSetSource()调用没有fnSetSource函数所需的2个参数。做我提到的第一个改变,你也许可以从那里找到答案


您不能制作一个单独的mxml组件的项目渲染器吗?

我快速查看了代码。fnSetSource()函数只有放在花括号内才会被调用:source=“{fnSetSource()}”

这将获得要调用的函数,但会出现错误,因为fnSetSource()调用没有fnSetSource函数所需的2个参数。做我提到的第一个改变,你也许可以从那里找到答案


无法使项目呈现器成为单独的mxml组件吗?

看起来您没有传递fnSetSource()所需的任何参数,因此在传递这两个参数之前,它将无法工作。。 这样使用你的函数
fnSetSource(value:Object,previousValue:Object,axis:IAxis):字符串

看起来您没有传递fnSetSource()所需的任何参数,因此在传递这两个参数之前它将无法工作。。 这样使用你的函数
fnSetSource(value:Object,previousValue:Object,axis:IAxis):String

如果您可以包含代码(或将其上载到某个地方),以便我们运行此示例,则可能会有人给出答案。。。没有办法,我正在阅读未格式化的代码:)请使用上的代码并用公共var费用替换数据提供程序:ArrayCollection=new ArrayCollection([{月:“一月”,利润:2000,费用:1500,isIncrease:true},{月:“二月”,利润:1000,费用:200,IsDecrese:false},{月:“三月”,利润:1500,费用:500,增加:真});如果isIncrease设置为true,则需要在y轴的月份旁边放置一个图标。如果isIncrease设置为false,则需要放置另一个图标。这可能吗?嗨,Brian,我已编辑了原始问题并给出了完整的代码。问题是:在fnSetSource()中,我试图设置图像的源,但它们是空的。请帮忙。我所做的是正确的还是我们不能在axis渲染器中获取图表数据项中的值?当您在categoryaxis中设置categoryField=“emplName”时,属性“data”指的是相应的axisrenderer中的什么?它只是emplName中的值还是数据提供程序中的整个对象?您明白了吗?想知道如果你做了plsIf你可以包括代码(或上传到某处),以便我们可以运行这个例子-有人可能会有一个答案。。。没有办法,我正在阅读未格式化的代码:)请使用上的代码并用公共var费用替换数据提供程序:ArrayCollection=new ArrayCollection([{月:“一月”,利润:2000,费用:1500,isIncrease:true},{月:“二月”,利润:1000,费用:200,IsDecrese:false},{月:“三月”,利润:1500,费用:500,增加:真});如果isIncrease设置为true,则需要在y轴的月份旁边放置一个图标。如果isIncrease设置为false,则需要放置另一个图标。这可能吗?嗨,Brian,我已编辑了原始问题并给出了完整的代码。问题是:在fnSetSource()中,我试图设置图像的源,但它们是空的。请帮忙。我所做的是正确的还是我们不能在axis渲染器中获取图表数据项中的值?当您在categoryaxis中设置categoryField=“emplName”时,属性“data”指的是相应的axisrenderer中的什么?它只是emplName中的值还是数据提供程序中的整个对象?您明白了吗?想知道如果你做了plsHi,很抱歉反应太晚。我通过不同的方法获得了功能。将其发布在此处,认为它对某人有用。创建自定义组件FormItemWithImage,扩展表单项。在此组件中,可以在creatChildren方法中添加图像。图像源和标签文本将由mxml提供。它工作得非常好。非常感谢您的宝贵意见。您好,很抱歉回复迟了。我通过不同的方法获得了功能。把它贴在这里想它会