我有自定义的柱形图,按以下顺序:
我可以获得#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 :(得分:0)
_chartItem.item.price= Math.abs( _chartItem.item.price);
你在这里丢失信息。可能不止一次绘制图表,第二次全部是正面和黑色。将原始值存储在其他变量中,这样就不会丢失。