我正在使用LineChart
aCategoryAxis
作为水平轴,我需要每个类别都有一个非常自定义的格式显示。UsingCategoryAxis.LabelFunction
对于我的目的来说还不够强大,因为它只允许对 Label 对象的文本字段进行自定义格式设置。特别是对于这个项目,我需要每个类别都是两个不同多行标签的网格或 HGroup。左标签需要左对齐,右标签需要右对齐。
我尝试创建一个自定义类,extends Group
并且implements IDataRenderer
. 但是,在public function set data(value:Object)
中定义的IDataRenderer
,似乎总是以值作为AxisLabel
对象调用,它不会在其中传递对象,只是一个字符串 ( AxisLabel.text
)
作为 hack-ey 的替代方案,我尝试使用 LabelFunction 来传递编码字符串,但即使这样也会导致问题。不知何故,这段代码不会在 CategoryAxis 上显示任何内容:
public class HeatmapAxisLabelRenderer
extends HGroup
implements IDataRenderer
{
public function HeatmapAxisLabelRenderer()
{
super();
this.includeInLayout = true;
this.visible = true;
this.width = 100;
this.height = 40;
// this.percentWidth = 100;
// this.percentHeight = 100;
}
// Internal variable for the property value.
private var _data:Object;
// Make the data property bindable.
[Bindable("dataChange")]
// Define the getter method.
public function get data():Object {
return _data;
}
// Define the setter method, and dispatch an event when the property
// changes to support data binding.
public function set data(value:Object):void {
_data = value;
if (value is AxisLabel && AxisLabel(value).text!=null) {
var parts:Array = AxisLabel(value).text.split("|~|");
if (parts.length != 2) return;
var name:Label = new Label();
name.text = parts[0];
name.setStyle("textAlign","left");
name.width = 100;
var limit:Label = new Label();
limit.text = parts[1];
limit.setStyle("textAlign","right");
limit.width = 100;
this.addElement(name);
this.addElement(limit);
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
} else {
trace("renderer bad value");
}
}