Flex categoryaxis font style Modification

Source: Internet
Author: User
Tags italic font

A friend in the group asked me how to modify the font size and color of one of flex charts visual labels: categoryaxis.

Definition of categoryaxis:
The categoryaxis class allows charts to represent data composed of discrete values on the axis. You can usually use the categoryaxis class to define a group of labels displayed along the axis of the chart. For example, charts that display data by city, year, or business department.
Inheritance relationship of categoryaxis:
Categoryaxis → axisbase → eventdispatcher → object
From the relationship above, we can see that categoryaxis does not inherit visualization containers such as uicomponent and displayobject, and categoryaxis does not have some attributes about text settings, such as fontsize, fontweight, and textdecoration.

However, we can use other methods to implement this function.
Categoryaxis has an attribute called labelfunction. Its definition is to specify a function that is used to define the tags generated by various projects in dataprovider of categoryaxis.

So the principle of modification: You can use labelfunction to get each label and then modify it.

FragmentCode:

<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;
}

Here, the categoryaxislabelfun parameter is as follows:
1. item: The text information in the label is saved.
2. prevvalue: the value of the previous category above the coordinate axis.
3. axis: instantiated object of categoryaxis.
4. categoryitem: the project in the dataprovider to be presented.
So there is only one parameter related to the tag: item.

The following code modifies the categoryaxis label:

1. Change the font size:
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. Change the font width:
Private function categoryaxislabelfun (item: object, prevvalue: object, axis: categoryaxis, categoryitem: Object): String {
VaR temp: String = item as string;
Return '<B>' + temp + </B> ';
}

3. Change the font underline:
Private function categoryaxislabelfun (item: object, prevvalue: object, axis: categoryaxis, categoryitem: Object): String {
VaR temp: String = item as string;
Return '<u>' + temp + </u> ';
}

4. Change the Italic font:
Private function categoryaxislabelfun (item: object, prevvalue: object, axis: categoryaxis, categoryitem: Object): String {
VaR temp: String = item as string;
Return '<I>' + temp + </I> ';
}

5. Change the font color:
Private function categoryaxislabelfun (item: object, prevvalue: object, axis: categoryaxis, categoryitem: Object): String {
VaR temp: String = item as string;
Return '<font color = "# ff0000">' + temp + </font> ';
}

To sum up, we actually use a very simple method to set its label using HTML tags.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.