2011-08-15 3 views
1

나는 플렉스 차트 구성 요소로 작업 해 왔으며 범례에 마커에 대한 사용자 정의 아이콘을 포함하려고합니다. 아이콘을 직접 설정하고 텍스트가 잘못 정렬되었지만 클래스 팩터 리 및 legendMarkerRenderer 속성을 사용하여 만든 경우 구성 요소가 잘 렌더링되는 이상한 동작이 발생했습니다. 아래에 문제를 설명하기 위해 스 니펫을 포함 시켰습니다.플렉스 차트의 LegendItem에 대한 사용자 정의 임베디드 마커

이 문제를 해결하는 것이 가능할 수 있지만 여기에 무슨 일이 일어날 지에 대한 설명이 있으면 궁금합니다.

추가 정보 : 플렉스 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> 
+0

마커에 이미지를 직접 삽입해도 작동하지 않는 이유는 모르겠지만 이미지에 포함 된 이미지를 래핑하고 이미지를 마커로 설정하면 레이아웃 기능이 올바르게 작동합니다. – Gizmo490

답변

1

<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" /> 

위해 일하는 것입니다, 이것은 거의 당신이 시작 것과 동일하지만 나는 명시 적 의해 BitmapAsset에 새로 만든 클래스 인스턴스를 캐스팅 .

+0

클래스 또는 클래스 팩토리를 인스턴스 (마커)에만 스타일 (legendMarkerRenderer)에 바인딩 할 수 없습니다. 나는 이것이 flex sdk의 버그라고 확신한다. 나는 대부분 버그가있는 곳을 아는 사람이 있는지를 대부분 묻고 있었다. 전설에 대한 코드를 파헤쳐 보면 두 번째 방법은 LegendItem이 Legend 클래스에 의해 생성되는 방법과 동일한 mxml입니다. 감사합니다. – Gizmo490

+0

임베드 된 애셋을 BitmapAsset으로 캐스팅하면 문제가 해결됩니다. 정말 고마워! – Gizmo490

관련 문제