---
title: "【转】Open Flash Chart支持中文字体旋转最新编译(Version 2 Lug Wyrm Charmer)"
author: "binyan17"
date: "2012-09-04T10:51:55Z"
tags: ["Flash", "ofc"]
categories: ["Web前端"]
slug: "open-flash-chart-version-2-lug-wyrm-charmer"
draft: false
lastmod: "2012-09-04T10:51:55Z"
id: 1670970
url: "https://binyan17.iteye.com/blog/1670970"
---

原文地址：[http://u.hooto.com/guangmean/blog/view/5213.html](http://u.hooto.com/guangmean/blog/view/5213.html)

之前写过一篇关于OFC的Blog，但没说清楚具体怎么编译，最近有朋友问到就再Blog一篇，希望对大家有所帮助。参见：http://www.hooto.com/home/guangmean/blog/archives/5159.html

编译Open Flash Chart II最新版本，系统环境：Linux + Flex\_Builder\_for\_Linux + Eclipse。

1.下载OFC最新版本源码http://teethgrinder.co.uk/open-flash-chart-2/downloads.php(这里下载的是Version 2 Lug Wyrm Charmer (28th,July 2009) )。

2.下载FlashDevelop http://www.flashdevelop.org/community/viewforum.php?f=11 因在ofc中引用了FlashDevelop里的2个包:org和mx (这里为FlashDevelop-3.0.6-RTM.exe)。

3.在Eclipse中新建一ActionScript项目，并命名为open\_flash\_chart(可自定义名称),然后导入Open Flash Chart的AS源码，该源码位于：open-flash-chart-2-Lug-Wyrm-Charmer/open-flash-chart文件夹下，同时导入FlashDevelop里的org包、mx包到改项目中。

4.下载中文字体Simsun.ttf，同样导入到open\_flash\_chart目录里。

5.下载Base64Encoder编码解码类，OFC里自带的Base64Encoder.as有问题，会导致编译时产生1162错误(Function does not have a body)，下载后直接覆盖open\_flash\_chart/mx/utils/Base64Encoder.as即可，下载地址：http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/utils/Base64Encoder.as。

6.嵌入我们的中文字体，共两处：

第一处：open\_flash\_chart/elements/axis/XAxisLabels.as 找到源码中这一行： \[Embed(systemFont = 'Arial', fontName = 'spArial', mimeType = 'application/x-font')] 注释掉该行并在下一行加入：\[Embed(source = '/home/guangmean/workspace/open\_flash\_chart/simsun.ttf', fontFamily = 'SimSun')]

第二处：open\_flash\_chart/elements/labels/YLegendBase.as 找到源码中这一行：   \[Embed(systemFont = 'Arial', fontName = 'spArial', mimeType = 'application/x-font')] 同上,注释掉该行并在下一行加入：\[Embed(source = '/home/guangmean/workspace/open\_flash\_chart/simsun.ttf', fontFamily = 'SimSun')]

7.经过步骤6我们就已经导入了中文字体，但是现在的X坐标中的中文还不会旋转(表现为X坐标的值都不见了)。为此我们还需要再次修改第6步中的XAxisLabels.as和YLegendBase.as源代码：将XAxisLabels.as中make\_label()方法里的fmt.font = "spArial"改为fmt.font = "SimSun"，YLegendBase.as文件一样。

以下为可选步骤：

8.修改open\_flash\_chart/Loading.as文件，将dots:Number调整为一个合适的整数，spin.graphics.drawCircle(x,y,3)中的数字3可自行调整，调整后的效果就是Loading data...后的加载圆圈变漂亮了(原理很简单，根据三角函数和圆周率调整轨迹)。

9.修改open\_flash\_chart.as文件this.load\_external\_file(file);的上一行：var file:String = "../../data-files/\*.txt";将"../../data-files/\*.txt"替换为一个合适文件路径(这样做的目的是防止Web应用时ofc在获取数据失败是可以到你指定的地方读取默认数据，改善用户体验)。

10.Error # 2032 with https in IE(Test under IE6 IE7)，参考：http://forums.codecharge.com/posts.php?post\_id=97771

header("Cache-Control: cache, must-revalidate");  
header("Pragma: public");

OK!!! 打完收工

效果如下(分别旋转正负45度角)：