2010-11-23 78 views
0

我有柱形圖我定製,按以下順序:一個或另一個但不是兩者

  1. 如果列值爲負,列顏色爲紅色。否則,它的黑色
  2. 我然後改變它,這樣所有的數據將出現在x軸以上通過改變所有負值陽性

我能#1 &#2完美單獨顯示,但是當我嘗試實現這兩個,我只得到黑色列(即代碼將負值轉換爲正值,然後將應用顏色,因此所有列都是黑色的......即使在我的代碼中,我已將顏色應用於關於如何糾正這個問題的任何建議?

以下是我的動作代碼:

package utils 
{ 
import mx.core.IDataRenderer; 
import mx.core.UIComponent; 
import flash.display.Graphics; 
import flash.geom.Rectangle; 
import mx.charts.ChartItem; 
import mx.charts.ColumnChart; 
import mx.charts.chartClasses.LegendData; 

public class ColorColumnChartRenderer extends UIComponent implements IDataRenderer 
{ 

    public function ColorColumnChartRenderer():void 
    { 
     super(); 
    } 
    private var _chartItem:ChartItem; 

public function set data(value:Object):void 
    { 
     if (_chartItem == value) 
      return; 
      // setData also is executed if there is a Legend Data 
      //defined for the chart. We validate that only chartItems are 
      //assigned to the chartItem class. 
     if (value is LegendData) 
      return; 
     _chartItem = ChartItem(value); 

    } 
    public function get data():Object 
    { 
     return _chartItem; 
    } 



override protected function 
updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void 
{ 
    super.updateDisplayList(unscaledWidth, unscaledHeight); 

    var rc:Rectangle = new Rectangle(0, 0, width , height); 
    var columnColor:uint; 
    var g:Graphics = graphics; 
     g.clear();   
     g.moveTo(rc.left,rc.top); 
     // Only if the _chartItem has data 
     if (_chartItem == null) 
      return; 
     // Only if the _chartItem has the attributes 
     if(_chartItem.item.hasOwnProperty("price")) 
     { 
      if (Number(_chartItem.item.price) > 0){ 
      // black 
          g.beginFill(0x000000);   
      } 

      if (Number(_chartItem.item.price) < 0){ 
       // red 
       g.beginFill(0xF04448);   
      } 
     }  

     // Draw the column 
     g.lineTo(rc.right,rc.top); 
     g.lineTo(rc.right,rc.bottom); 
     g.lineTo(rc.left,rc.bottom); 
     g.lineTo(rc.left,rc.top); 
     g.endFill(); 

     _chartItem.item.price= Math.abs(_chartItem.item.price); 

    } 
} 
} 

回答

0
_chartItem.item.price= Math.abs(_chartItem.item.price); 

您在這裏丟失信息。可能是圖表不止一次繪製,第二次都是正面和黑色。將原始值存儲在其他變量中,以免丟失。

相關問題