flex 图表categoryField设置 labelFunction使用

CategoryAxis有一个叫做labelFunction的属性,这个属性的定义:指定一个函数,用于定义为CategoryAxis的dataProvider中的各个项目生成的标签。

所以修改的原理:可以利用labelFunction得到每个Label,然后再对其进行修改。

片段代码:
<mx:horizontalAxis>
  <mx:CategoryAxis id="ca"
         categoryField="@date" title="August 2007" labelFunction="categoryAxisLabelFun" />
</mx:horizontalAxis>
 
private function categoryAxisLabelFun( item : Object, prevValue : Object, axis : CategoryAxis, categoryItem : Object) : String {
      var temp : String = item as String;
      return temp;
}

其中categoryAxisLabelFun的参数:
1、item:保存的就是Label里面文字信息。
2、prevValue:坐标轴上面,前一个类别的值。
3、axis:CategoryAxis的实例化对象。
4、categoryItem:是将要呈现的dataProvider中的项目。
所以与标签有关系的只有第一个参数:item。
 
以下代码分别是对CategoryAxis的标签进行修改的代码:
 
1、改变字体大小:
private function categoryAxisLabelFun( item : Object, prevValue : Object, axis : CategoryAxis, categoryItem : Object) : String {
      var temp : String = item as String;
      return  '<font size="20">' + temp + </font>';
}

2、改变字体粗细:
private function categoryAxisLabelFun( item : Object, prevValue : Object, axis : CategoryAxis, categoryItem : Object) : String {
      var temp : String = item as String;
      return  '<B>' + temp + </B>';
}

3、改变字体下划线:
private function categoryAxisLabelFun( item : Object, prevValue : Object, axis : CategoryAxis, categoryItem : Object) : String {
      var temp : String = item as String;
      return  '<U>' + temp + </U>';
}

4、改变字体斜体:
private function categoryAxisLabelFun( item : Object, prevValue : Object, axis : CategoryAxis, categoryItem : Object) : String {
      var temp : String = item as String;
      return  '<I>' + temp + </I>';
}

5、改变字体颜色:
private function categoryAxisLabelFun( item : Object, prevValue : Object, axis : CategoryAxis, categoryItem : Object) : String {
      var temp : String = item as String;
      return  '<font color="#ff0000">' + temp + </font>';
}

 

posted @ 2010-03-14 14:37  MXi4oyu  阅读(197)  评论(0编辑  收藏  举报