弹性图表中 LegendItem 的自定义嵌入标记

发布于 2024-11-29 23:59:48 字数 1235 浏览 1 评论 0原文

我一直在使用 Flex 图表组件,我想在图例中嵌入标记的自定义图标。我遇到了一些奇怪的行为,如果直接设置,图标会镜像并且文本未对齐,但如果使用类工厂和 legendMarkerRenderer 属性创建,则组件渲染得很好。我在下面添加了一个片段来说明问题。

解决这个问题可能是可能的,但我很好奇是否有人对这里可能发生的情况有解释。

其他信息:Flex SDK 4.5.0.20967、FlashBuilder 4.5

这是以下代码片段的输出:

Application Snippet

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Script>
    <![CDATA[
        import mx.charts.LegendItem;

        [Embed(source="/resources/GraphResetIcon.png")]
        public static var icon:Class;
    ]]>
    </fx:Script>
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <!-- This works fine -->
    <mx:LegendItem legendMarkerRenderer="{new ClassFactory(icon)}" markerAspectRatio="1" 
        labelPlacement="right" label="Texty texty" markerHeight="11" markerWidth="11" />

    <!-- This does not work -->
    <mx:LegendItem marker="{new icon()}" markerAspectRatio="1" labelPlacement="right"     
        label="Texty texty" markerHeight="11" markerWidth="11" />

</s:Application>

I've been working with the flex charting component and I want to embed a custom icon for the marker in the legend. I've run into some strange behaviour where if set directly the icon is mirrored and the text is misaligned but if created using the a class factory and the legendMarkerRenderer property the component renders fine. I've included a snippet to illustrate the problem below.

Working around this problem may be possible but I'm curious if anyone has an explanation as to what could be going on here.

Additional info: Flex SDK 4.5.0.20967, FlashBuilder 4.5

This is the output of the below snippet:

Application Snippet

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Script>
    <![CDATA[
        import mx.charts.LegendItem;

        [Embed(source="/resources/GraphResetIcon.png")]
        public static var icon:Class;
    ]]>
    </fx:Script>
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <!-- This works fine -->
    <mx:LegendItem legendMarkerRenderer="{new ClassFactory(icon)}" markerAspectRatio="1" 
        labelPlacement="right" label="Texty texty" markerHeight="11" markerWidth="11" />

    <!-- This does not work -->
    <mx:LegendItem marker="{new icon()}" markerAspectRatio="1" labelPlacement="right"     
        label="Texty texty" markerHeight="11" markerWidth="11" />

</s:Application>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2024-12-06 23:59:48

尝试

<mx:LegendItem marker="{icon}" markerAspectRatio="1" labelPlacement="right"              label="Texty texty" markerHeight="11" markerWidth="11" /> 

编辑:

我挖出了我的备份硬盘驱动器,这对我有用

//button icons          
[Embed(source='com/magnoliamultimedia/assets/guess.png')]
private var guessIcon:Class;
[Embed(source='com/magnoliamultimedia/assets/half_guess.png')]
private var halfGuessIcon:Class;
[Embed(source='com/magnoliamultimedia/assets/not_guess.png')]
//bitmapasset for markers
[Bindable]
private var _guessBA:BitmapAsset;
[Bindable]
private var _halfGuessBA:BitmapAsset;
[Bindable]
private var _notGuessBA:BitmapAsset;

///...
private function init():void{
    _guessBA = BitmapAsset(new guessIcon());
    _halfGuessBA = BitmapAsset(new halfGuessIcon());
    _notGuessBA= BitmapAsset(new notGuessIcon());
    _markerHeight = _guessBA.height*.75;
    _markerWidth = _guessBA.width*.75;
    legend.visible = true;
}
//...
<mx:Canvas id="legend" width="{Application.application.width}" height="75" 
    backgroundColor="#FFFFFF" visible="false">
    <mx:constraintColumns>
        <mx:ConstraintColumn id="rowName" width="20%" />
        <mx:ConstraintColumn id="legend1" width="25%" />
        <mx:ConstraintColumn id="legend2" width="25%" />
        <mx:ConstraintColumn id="legend3" width="25%" />
    </mx:constraintColumns>
    <mx:constraintRows>
        <mx:ConstraintRow id="colors" />
        <mx:ConstraintRow id="icons" />
    </mx:constraintRows>
    <!--color legends-->
    <mx:LegendItem label="Colors:" id="colorCol1" visible="false"
            top="colors:10" left="rowName:10" right="legend1:10" fill="{noFill}"
            markerHeight="0" markerWidth="0" />
    <mx:LegendItem label="Correct" id="colorCol2" visible="false"
            top="colors:10" left="legend1:10" right="legend2:10" 
            fill="{greenFill}" stroke="{outline}" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
    <mx:LegendItem label="Wrong" id="colorCol3" visible="false"
            top="colors:10" left="legend2:10" right="legend3:10" 
            fill="{redFill}" stroke="{outline}" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
    <mx:LegendItem label="Not Attempted" id="colorCol4" visible="false"
            top="colors:10" left="legend3:10" 
            fill="{defaultFill}" stroke="{outline}" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
    <mx:HRule id="separator" top="icons:5" left="10" right="10" visible="false" />
        <!--icon legends-->
        <mx:LegendItem label="Icons:" 
            top="icons:10" left="rowName:10" right="legend1" fill="{noFill}" 
            markerHeight="0" markerWidth="0" />
        <mx:LegendItem label="Guess" 
            top="icons:10" left="legend1:10" right="legend2:10" 
            marker="{_guessBA}" markerAspectRatio="1" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
        <mx:LegendItem label="Half Guess" 
            top="icons:10" left="legend2:10" right="legend3:10" 
            marker="{_halfGuessBA}" markerAspectRatio="1" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
        <mx:LegendItem label="Not A Guess" 
            top="icons:10" left="legend3:10" 
            marker="{_notGuessBA}" markerAspectRatio="1" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
</mx:Canvas>
<!--legend colors-->
<mx:SolidColor id="redFill" color="0x990000" />
<mx:SolidColor id="greenFill" color="0x003300" />
<mx:SolidColor id="defaultFill" color="0xE6EEEE" />
<mx:SolidColor id="noFill" color="0xE6EEEE" alpha="0" />
<mx:Stroke id="outline" color="0" weight="1" />

原则上,这与您开始时几乎相同,但我将新创建的 Class 实例显式转换为 BitmapAsset。

Try

<mx:LegendItem marker="{icon}" markerAspectRatio="1" labelPlacement="right"              label="Texty texty" markerHeight="11" markerWidth="11" /> 

Edit:

I dug out my backup hard drive, and here is what works for me

//button icons          
[Embed(source='com/magnoliamultimedia/assets/guess.png')]
private var guessIcon:Class;
[Embed(source='com/magnoliamultimedia/assets/half_guess.png')]
private var halfGuessIcon:Class;
[Embed(source='com/magnoliamultimedia/assets/not_guess.png')]
//bitmapasset for markers
[Bindable]
private var _guessBA:BitmapAsset;
[Bindable]
private var _halfGuessBA:BitmapAsset;
[Bindable]
private var _notGuessBA:BitmapAsset;

///...
private function init():void{
    _guessBA = BitmapAsset(new guessIcon());
    _halfGuessBA = BitmapAsset(new halfGuessIcon());
    _notGuessBA= BitmapAsset(new notGuessIcon());
    _markerHeight = _guessBA.height*.75;
    _markerWidth = _guessBA.width*.75;
    legend.visible = true;
}
//...
<mx:Canvas id="legend" width="{Application.application.width}" height="75" 
    backgroundColor="#FFFFFF" visible="false">
    <mx:constraintColumns>
        <mx:ConstraintColumn id="rowName" width="20%" />
        <mx:ConstraintColumn id="legend1" width="25%" />
        <mx:ConstraintColumn id="legend2" width="25%" />
        <mx:ConstraintColumn id="legend3" width="25%" />
    </mx:constraintColumns>
    <mx:constraintRows>
        <mx:ConstraintRow id="colors" />
        <mx:ConstraintRow id="icons" />
    </mx:constraintRows>
    <!--color legends-->
    <mx:LegendItem label="Colors:" id="colorCol1" visible="false"
            top="colors:10" left="rowName:10" right="legend1:10" fill="{noFill}"
            markerHeight="0" markerWidth="0" />
    <mx:LegendItem label="Correct" id="colorCol2" visible="false"
            top="colors:10" left="legend1:10" right="legend2:10" 
            fill="{greenFill}" stroke="{outline}" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
    <mx:LegendItem label="Wrong" id="colorCol3" visible="false"
            top="colors:10" left="legend2:10" right="legend3:10" 
            fill="{redFill}" stroke="{outline}" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
    <mx:LegendItem label="Not Attempted" id="colorCol4" visible="false"
            top="colors:10" left="legend3:10" 
            fill="{defaultFill}" stroke="{outline}" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
    <mx:HRule id="separator" top="icons:5" left="10" right="10" visible="false" />
        <!--icon legends-->
        <mx:LegendItem label="Icons:" 
            top="icons:10" left="rowName:10" right="legend1" fill="{noFill}" 
            markerHeight="0" markerWidth="0" />
        <mx:LegendItem label="Guess" 
            top="icons:10" left="legend1:10" right="legend2:10" 
            marker="{_guessBA}" markerAspectRatio="1" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
        <mx:LegendItem label="Half Guess" 
            top="icons:10" left="legend2:10" right="legend3:10" 
            marker="{_halfGuessBA}" markerAspectRatio="1" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
        <mx:LegendItem label="Not A Guess" 
            top="icons:10" left="legend3:10" 
            marker="{_notGuessBA}" markerAspectRatio="1" 
            markerHeight="{_markerHeight}" markerWidth="{_markerWidth}" />
</mx:Canvas>
<!--legend colors-->
<mx:SolidColor id="redFill" color="0x990000" />
<mx:SolidColor id="greenFill" color="0x003300" />
<mx:SolidColor id="defaultFill" color="0xE6EEEE" />
<mx:SolidColor id="noFill" color="0xE6EEEE" alpha="0" />
<mx:Stroke id="outline" color="0" weight="1" />

In principle, this is almost the same as what you started out with, but I explicitly cast the newly created Class instance to BitmapAsset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文