2010-03-22 4 views
5

플렉스 차트에서 특정 시리즈와 관련된 "참조 라인"과 같은 것을 그리기를 원합니다. 따라서이 라인은 독립 시리즈가 아니며 범례에 표시하면 안됩니다. 차트 범례에서 일부 계열을 제외 할 수 있습니까? 감사합니다.범례 시리즈를 제외하는 방법

답변

7

차트 범례에서 일부 계열을 제외 할 수 있습니다.

모든 차트 클래스 (ChartBase 확장)에는 legendData Array 속성이 있습니다. 이 legendData에는 LegendItem의 목록이 있습니다. LegendData를 기반으로하지만 원하는 LegendItem 만 사용하여 newArray를 만드는 경우 그 배열을 범례에 대한 dataProvider로 설정할 수 있습니다.

또한 처음부터 만드는 LegendItems를 기반으로하는 LegendItem의 고유 한 배열을 만들 수 있습니다. 그리고 그 배열을 범례의 dataProvider로 사용하십시오. 이 동적에 반영하기 위해 내가 루이스 B의 대답에 정교

<mx:Script> 
    <![CDATA[ 
     private function cc(event:Event):void 
     { 
      var newArray:Array = new Array(); 
      newArray.push(myChart.legendData[0]); 
      newArray.push(myChart.legendData[2]); 

      myActionScriptLegend.dataProvider = newArray; 
     } 
    ]]> 
</mx:Script> 

<mx:ColumnChart id="myChart"> 
    <mx:series> 
     <mx:ColumnSeries id="series0"/> 
     <mx:ColumnSeries id="series1"/> 
     <mx:ColumnSeries id="series2"/> 
    </mx:series> 
</mx:ColumnChart> 
<mx:Legend dataProvider="{[myChart.legendData[0],myChart.legendData[2]]}" /> 
<mx:Legend id="myActionScriptLegend" creationComplete="cc(event)" /> 

http://livedocs.adobe.com/flex/3/langref/mx/charts/chartClasses/ChartBase.html#legendData
http://livedocs.adobe.com/flex/3/langref/mx/charts/LegendItem.html
http://livedocs.adobe.com/flex/3/html/charts_displayingdata_12.html#330954

+0

감사합니다. actionscript에서도 사용할 수 있습니까? –

+1

ActionScript에서 동일한 작업을 수행하는 두 번째 범례 (id = "myActionScriptLegend")를 제공했습니다. 희망이 도움이됩니다. –

+0

Luis 덕분에 많은 시간을 죽이는 문제를 해결할 수있었습니다. – Anoop

10

:

예를 들어, 여기 난 단지 내 전설의 첫 번째와 세 번째 시리즈를 표시 라인 챠트의 데이터 제공자. 이렇게하면 범례에는 차트에서 사용할 수있는 필드 만 표시됩니다. 멋지네. 여기

내가 생각 해낸 무엇이며, 그것은 잘 작동 :

 protected function onUpdateLinechartComplete(e:FlexEvent):void 
     { 

      //empty legend for fresh display 
      var legendArray:Array = new Array(); 
      legend1.dataProvider = legendArray; 

      //filter Legend data so that only LineSeries with data can be shown 
      for(var i:int=0; i< linechart1.legendData.length; i++) { 

       //if data is found in the line series, let's add it to the chart legend data provider, so it can be displayed in the legend 
       if (linechart1.legendData[i].element.items.length != 0) { 
        legendArray.push(linechart1.legendData[i]); 
       } 

      } 
      legend1.dataProvider = legendArray; 
      legend1.direction = "vertical"; 
     } 



//in the page Initialize function, I add a listener event to the linechart component for when the legend update completes so it can filter lineseries on the legend's dataprovider in [onUpdateLegendComplete] 
linechart1.addEventListener(FlexEvent.UPDATE_COMPLETE, onUpdateLinechartComplete); 

나는이 이벤트 핸들러를 사용할 필요하고, 선 차트 자체에 이벤트 리스너를 부착 끝났다. 전설의 데이터 제공 업체와 경쟁 조건이 발생했기 때문입니다. Sometmes가 작동 할 때가 있고 때로는 그렇지 않을 수도 있습니다. 이벤트 리스너를 사용하면 해당 문제가 제거되고 선형 차트에서 데이터로드가 완료되면 범례 만 필터링됩니다.

이 답변을 신속하게 업데이트 할 수 있도록 FLEX FOLKS !! 이미 어쨌든 사용자 정의 선 차트 클래스가있는 경우 devtron의 대답의 또 다른 버전은, 내가 다음에 넣고 한 것처럼

+1

나는 그것을 좋아한다. 아마 다른 대답은 OP에 대해 실제로 맞지만 이것이 필요한 것입니다. – Fletch

4

OK :

[Bindable] public var activeLegendData:Array; 

// this goes in an initialize handler 
addEventListener(FlexEvent.UPDATE_COMPLETE, onUpdateChartComplete); 

protected function onUpdateChartComplete(e:FlexEvent):void { 
    activeLegendData = new Array(); 
    for(var i:int=0; i < legendData.length; i++) { 
     if (legendData[i].element.items.length != 0) { 
      activeLegendData.push(legendData[i]); 
     } 
    } 
} 

는 그런 다음 linechart.activeLegendData 대신 선 차트에 범례의 dataProvider를 바인딩합니다.

Devtron의 솔루션보다이 솔루션의 장점은 앱에 다른 선형 차트를 삽입 할 때마다 코드를 다시 작성할 필요가 없다는 것입니다.

+0

나는 이것이 내 대답과 다른 점을 알고있다. – D3vtr0n

1

또 다른 대안 ...

legendData()의 게터을 무시하고 빈 배열을 반환, 차트 계열 클래스 중 하나에서 새 클래스를 파생. 다음은 PlotSeries의 예입니다.

public class PlotSeriesNoLegend extends PlotSeries 
{ 
    public function PlotSeriesNoLegend() 
    { 
     super(); 
    } 

    override public function get legendData():Array /* of LegendData */ 
    { 
     return [ ]; 
    } 
} 
0

일부 답변은 이전 답변에 대한 설명입니다. 레전으로 사용하기 위해 새 배열을 만들 때 참조 할 때 설명 된 것과 같지 않으므로주의하십시오.나를 위해 그것은 이렇게 작동합니다 :

기존 pie.legendData의 값에 액세스하려고하면 다음과 같이해야합니다. pie.legendData [0] [0] 또는 pie.legendData [0] [1] ]

게다가 이러한 데이터를 새 배열로 가져와 새 범례를 만드는 데 사용하려면 파이가 이미 만들어 질 때까지 기다려야합니다.

나는 단순히 파이의 렌더 이벤트를 사용한다.

은 당신을 도움이되기를 바랍니다.