open-flash-chart
早就听说了open-flash-chart,可一直没有机会认识。现在项目里需要一个图表,我第一时间就想到了他,虽然版本很多,但是我还是下载了1.9.7。
下载完肯定是怎么使用了,在网上找了很久,都没有办法成功。可能我这人比较懒吧,总是希望拿来就能用,可是总是让人失望。网上找来的都是用js实现的,我想用C#一下就搞定。但是网上实在找不到一点点的提示,于是只能自己摸索了。
打开源项目,因为我想实现的是饼图,所以我一下就找到了OpenFlashChart.Charts.Pie的类,看了一下。于是就开始了做到自己项目中去,因为是摸索的,所以可能方法不是最好的,希望大家能指正并指导。
首先编译源项目,将生成的dll引用到自己的项目中去。其次我又找到了OpenFlashChartLibrary.dll,还说什么呢,直接加到工具箱里去吧。然后,然后呢,当然是直接拖到页面上来用啊,如:
ofc:OpenFlashChartControl ID="OpenFlashChartControl1" runat="server" dataSource="GraphData.aspx"
isDataSourceExternal="true" isSwfObjectEnabled="true" Visible="true" heightPx="400">
接下来就是搞定datasource了。
penFlashChart.Charts.Pie myPie = new OpenFlashChart.Charts.Pie(60, "#9933CC", "#000000");
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(20,"运行一处","#9933CC"));
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(30,"信息设备科","#0000CC"));
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(40,"秘书处","#AAAAFF"));
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(10,"岭奥核电","#202020"));
Response.Clear();
Response.Write(myPie.ToString());
Response.End();
运行一下看看吧,靠,帅呆了,效果出来了。但是不完美啊,没有标题。于是又拿出源码看看。最后修改如下:
OpenFlashChart.Graph graph = new OpenFlashChart.Graph();
OpenFlashChart.Charts.Pie myPie = new OpenFlashChart.Charts.Pie(60, "#9933CC", "#000000");
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(20,"运行一处","#9933CC")); myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(30,"信息设备科","#0000CC")); myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(40,"秘书处","#AAAAFF")); myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(10,"岭奥核电","#202020")); OpenFlashChart.Title title = new OpenFlashChart.Title("按成本中心汇总图", "{font-size:20px; color:#8B3626}" graph.Pie = myPie; graph.Title = title; Response.Clear(); Response.Write(graph.ToString()); Response.End();
下载完肯定是怎么使用了,在网上找了很久,都没有办法成功。可能我这人比较懒吧,总是希望拿来就能用,可是总是让人失望。网上找来的都是用js实现的,我想用C#一下就搞定。但是网上实在找不到一点点的提示,于是只能自己摸索了。
打开源项目,因为我想实现的是饼图,所以我一下就找到了OpenFlashChart.Charts.Pie的类,看了一下。于是就开始了做到自己项目中去,因为是摸索的,所以可能方法不是最好的,希望大家能指正并指导。
首先编译源项目,将生成的dll引用到自己的项目中去。其次我又找到了OpenFlashChartLibrary.dll,还说什么呢,直接加到工具箱里去吧。然后,然后呢,当然是直接拖到页面上来用啊,如:
ofc:OpenFlashChartControl ID="OpenFlashChartControl1" runat="server" dataSource="GraphData.aspx"
isDataSourceExternal="true" isSwfObjectEnabled="true" Visible="true" heightPx="400">
接下来就是搞定datasource了。
penFlashChart.Charts.Pie myPie = new OpenFlashChart.Charts.Pie(60, "#9933CC", "#000000");
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(20,"运行一处","#9933CC"));
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(30,"信息设备科","#0000CC"));
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(40,"秘书处","#AAAAFF"));
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(10,"岭奥核电","#202020"));
Response.Clear();
Response.Write(myPie.ToString());
Response.End();
运行一下看看吧,靠,帅呆了,效果出来了。但是不完美啊,没有标题。于是又拿出源码看看。最后修改如下:
OpenFlashChart.Graph graph = new OpenFlashChart.Graph();
OpenFlashChart.Charts.Pie myPie = new OpenFlashChart.Charts.Pie(60, "#9933CC", "#000000");
myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(20,"运行一处","#9933CC")); myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(30,"信息设备科","#0000CC")); myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(40,"秘书处","#AAAAFF")); myPie.Data.Add(new OpenFlashChart.Charts.Pie.Piece(10,"岭奥核电","#202020")); OpenFlashChart.Title title = new OpenFlashChart.Title("按成本中心汇总图", "{font-size:20px; color:#8B3626}" graph.Pie = myPie; graph.Title = title; Response.Clear(); Response.Write(graph.ToString()); Response.End();