(1)饼状图:----通过修改参数生成不同的走势图,

string strCategory = "优良率" + '\t' + "合格率" + '\t' + "不合格率";

string strValue = a.ToString("F3") + '\t' + b.ToString("F3") + '\t' + c.ToString("F3");

string path=Server.MapPath("~/File/Graphs");

string mTitle = "施工安全评定等级饼形图";

string xTitle = "";

string yTitle = "";

int imgWidth = 1000;

int imgHeight =400;

int chartType = 18;//设置生成图表的种类

// this.CreateChartSmoothLine(strCategory,strValue,mTitle,xTitle,yTitle,imgWidth,imgHeight,chartType);

FishPro.OWCChart11 chart = new OWCChart11(path, "评级", mTitle,chartType, xTitle, yTitle, imgWidth, imgHeight);

chart.OCategory = strCategory;

chart.OValue = strValue;

if (chart.Create())

{

this.Image1.ImageUrl ="~/File/Graphs/"+chart.FileName;

}

else

{

Messabox.ShowError(this, "生成失败");

(2)添加类:

public class OWCChart11

{

#region 属性

private string m_SavePath;

private string m_Category;

private string m_Value;

private DataTable m_DataSource;

private string m_SeriesName;

private string m_Title;

private string m_AxesXTitle;

private string m_AxesYTitle;

private int m_PicWidth;

private int m_PicHeight;

private int m_Type;

private string m_FileName;

/**/

/// <summary>

/// 保存图片的路径和名称,物理路径

/// </summary>

public string SavePath

{

get { return m_SavePath; }

set { m_SavePath = value; }

}

/**/

/// <summary>

/// 直接获得类型

/// </summary>

public string OCategory

{

get { return m_Category; }

set { m_Category = value; }

}

/**/

/// <summary>

/// 直接获得值

/// </summary>

public string OValue

{

get { return m_Value; }

set { m_Value = value; }

}

/**/

/// <summary>

/// 以表格DataTable的形式获取原始数据

/// </summary>

public DataTable DataSource

{

get { return m_DataSource; }

set

{

m_DataSource = value;

m_Category = GetColumnsStr(m_DataSource);

m_Value = GetValueStr(m_DataSource);

}

}

/**/

/// <summary>

/// 简要说明

/// </summary>

public string SeriesName

{

get { return m_SeriesName; }

set { m_SeriesName = value; }

}

/**/

/// <summary>

/// 图表的总标题,说明图表的简单意思

/// </summary>

public string Title

{

get { return m_Title; }

set { m_Title = value; }

}

/**/

/// <summary>

/// 图表横坐标标题,说明横坐标的意义

/// </summary>

public string AxesXTitle

{

get { return m_AxesXTitle; }

set { m_AxesXTitle = value; }

}

/**/

/// <summary>

/// 图表纵坐标标题,说明纵坐标的意义

/// </summary>

public string AxesYTitle

{

get { return m_AxesYTitle; }

set { m_AxesYTitle = value; }

}

/**/

/// <summary>

///  生成的图片宽度

/// </summary>

public int PicWidth

{

get { return m_PicWidth; }

set { m_PicWidth = value; }

}

/**/

/// <summary>

///  生成的图片高度

/// </summary>

public int PicHeight

{

get { return m_PicHeight; }

set { m_PicHeight = value; }

}

/**/

/// <summary>

/// 类型

/// chChartTypeColumnStacked100 =2

///chChartTypeColumnStacked1003D = 49

///chChartTypeColumnStacked3D = 48

///chChartTypeCombo = -1

///chChartTypeCombo3D = -2

///chChartTypeDoughnut = 32

///chChartTypeDoughnutExploded = 33

///chChartTypeLine = 6

///chChartTypeLine3D = 54

///chChartTypeLineMarkers=  7

///chChartTypeLineOverlapped3D=  55

///chChartTypeLineStacked = 8

///chChartTypeLineStacked100  =10

///chChartTypeLineStacked1003D=  57

///chChartTypeLineStacked100Markers = 11

///chChartTypeLineStacked3D = 56

///chChartTypeLineStackedMarkers = 9

///chChartTypePie = 18

///chChartTypePie3D =58

///chChartTypePieExploded = 19

///chChartTypePieExploded3D = 59

///chChartTypePieStacked = 20

///chChartTypePolarLine = 42

///chChartTypePolarLineMarkers = 43

///chChartTypePolarMarkers = 41

///chChartTypePolarSmoothLine = 44

///chChartTypePolarSmoothLineMarkers = 45

///chChartTypeRadarLine=  34

///chChartTypeRadarLineFilled = 36

///chChartTypeRadarLineMarkers=  35

///chChartTypeRadarSmoothLine = 37

///chChartTypeRadarSmoothLineMarkers = 38

///chChartTypeScatterLine = 25

///chChartTypeScatterLineFilled = 26

///chChartTypeScatterLineMarkers = 24

///chChartTypeScatterMarkers = 21

///chChartTypeScatterSmoothLine = 23

///chChartTypeScatterSmoothLineMarkers = 22

///chChartTypeSmoothLine = 12

///chChartTypeSmoothLineMarkers = 13

///chChartTypeSmoothLineStacked = 14

///chChartTypeSmoothLineStacked100 = 16

///chChartTypeSmoothLineStacked100Markers = 17

///chChartTypeSmoothLineStackedMarkers = 15

///chChartTypeStockHLC = 39

///chChartTypeStockOHLC = 40

/// </summary>

public int Type

{

get { return m_Type; }

set { m_Type = value; }

}

public string FileName

{

get { return m_FileName; }

set

{

m_FileName = value;

if (m_FileName == null || m_FileName == "")

{

m_FileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif";//生成图片名称

}

}

}

/**/

/// <summary>

/// 是DataTable的转换

/// </summary>

/// <param name="dt"></param>

/// <returns></returns>

private string GetColumnsStr(DataTable dt)

{

StringBuilder strList = new StringBuilder();

foreach (DataRow r in dt.Rows)

{

strList.Append(r[0].ToString() + '\t');

}

return strList.ToString();

}

/**/

/// <summary>

/// 是DataTable的转换

/// </summary>

/// <param name="dt"></param>

/// <returns></returns>

private string GetValueStr(DataTable dt)

{

StringBuilder strList = new StringBuilder();

foreach (DataRow r in dt.Rows)

{

strList.Append(r[1].ToString() + '\t');

}

return strList.ToString();

}

#endregion

#region 枚举类型

/**/

/// <summary>

/// 枚举类型 对应于OWC的图表类型

/// </summary>

public enum ChartType : int

{

/**/

/// <summary>

/// 面积图

/// </summary>

chChartTypeArea = 29,

/**/

/// <summary>

/// 面积图3D

/// </summary>

chChartTypeArea3D = 60,

/**/

/// <summary>

/// 面积图重复

/// </summary>

chChartTypeAreaOverlapped3D = 61,

/**/

/// <summary>

/// 堆积面积图

/// </summary>

chChartTypeAreaStacked = 30,

/**/

/// <summary>

/// 堆积面积图百分比图

/// </summary>

chChartTypeAreaStacked100 = 31,

/**/

/// <summary>

/// 堆积面积图百分比图3D

/// </summary>

chChartTypeAreaStacked1003D = 63,

/**/

/// <summary>

/// 堆积面积图3D

/// </summary>

chChartTypeAreaStacked3D = 62,

/**/

/// <summary>

/// 横道图3D

/// </summary>

chChartTypeBar3D = 50,

/**/

/// <summary>

/// 横道图串风格

/// </summary>

chChartTypeBarClustered = 3,

/**/

/// <summary>

/// 横道图串风格3D

/// </summary>

chChartTypeBarClustered3D = 51,

/**/

/// <summary>

/// 堆横道图

/// </summary>

chChartTypeBarStacked = 4,

/**/

/// <summary>

/// 堆横道图百分比图

/// </summary>

chChartTypeBarStacked100 = 5,

/**/

/// <summary>

/// 堆横道图百分比图3D

/// </summary>

chChartTypeBarStacked1003D = 53,

/**/

/// <summary>

/// 堆横道图3D

/// </summary>

chChartTypeBarStacked3D = 52,

/**/

/// <summary>

/// 气泡图

/// </summary>

chChartTypeBubble = 27,

/**/

/// <summary>

/// 线形气泡图

/// </summary>

chChartTypeBubbleLine = 28,

/**/

/// <summary>

/// 柱形图

/// </summary>

chChartTypeColumn3D = 46,

/**/

/// <summary>

/// 3D柱形图

/// </summary>

chChartTypeColumnClustered = 0,

/**/

/// <summary>

/// 3D串柱形图

/// </summary>

chChartTypeColumnClustered3D = 47,

/**/

/// <summary>

/// 重叠柱形图

/// </summary>

chChartTypeColumnStacked = 1,

/**/

/// <summary>

/// 100%重叠柱形图

/// </summary>

chChartTypeColumnStacked100 = 2,

/**/

/// <summary>

/// 100%3D重叠柱形图

/// </summary>

chChartTypeColumnStacked1003D = 49,

/**/

/// <summary>

/// 3D柱形图

/// </summary>

chChartTypeColumnStacked3D = 48,

/**/

/// <summary>

/// 组合图

/// </summary>

chChartTypeCombo = -1,

/**/

/// <summary>

/// 3D组合图

/// </summary>

chChartTypeCombo3D = -2,

/**/

/// <summary>

/// 环形图

/// </summary>

chChartTypeDoughnut = 32,

/**/

/// <summary>

/// 破式环形图

/// </summary>

chChartTypeDoughnutExploded = 33,

/**/

/// <summary>

/// 折线图

/// </summary>

chChartTypeLine = 6,

/**/

/// <summary>

/// 3D折线图

/// </summary>

chChartTypeLine3D = 54,

/**/

/// <summary>

/// 制造折线图

/// </summary>

chChartTypeLineMarkers = 7,

/**/

/// <summary>

/// 重复折线图

/// </summary>

chChartTypeLineOverlapped3D = 55,

/**/

/// <summary>

/// 重叠折线图

/// </summary>

chChartTypeLineStacked = 8,

/**/

/// <summary>

/// 100%重叠折线图

/// </summary>

chChartTypeLineStacked100 = 10,

/**/

/// <summary>

/// 100%3D重叠折线图

/// </summary>

chChartTypeLineStacked1003D = 57,

/**/

/// <summary>

/// 制造100%重叠折线图

/// </summary>

chChartTypeLineStacked100Markers = 11,

/**/

/// <summary>

/// 3D重叠折线图

/// </summary>

chChartTypeLineStacked3D = 56,

/**/

/// <summary>

/// 制造重叠折线图

/// </summary>

chChartTypeLineStackedMarkers = 9,

/**/

/// <summary>

/// 饼图

/// </summary>

chChartTypePie = 18,

/**/

/// <summary>

/// 3D饼图

/// </summary>

chChartTypePie3D = 58,

/**/

/// <summary>

/// 破式饼图

/// </summary>

chChartTypePieExploded = 19,

/**/

/// <summary>

/// 3D破式饼图

/// </summary>

chChartTypePieExploded3D = 59,

/**/

/// <summary>

/// 重叠饼图

/// </summary>

chChartTypePieStacked = 20,

/**/

/// <summary>

/// 极坐标图

/// </summary>

chChartTypePolarLine = 42,

/**/

/// <summary>

/// 制造线形极坐标图

/// </summary>

chChartTypePolarLineMarkers = 43,

/**/

/// <summary>

/// 制造极坐标图

/// </summary>

chChartTypePolarMarkers = 41,

/**/

/// <summary>

/// 平滑线形极坐标图

/// </summary>

chChartTypePolarSmoothLine = 44,

/**/

/// <summary>

/// 制造平滑线形极坐标图

/// </summary>

chChartTypePolarSmoothLineMarkers = 45,

/**/

/// <summary>

/// 雷达图

/// </summary>

chChartTypeRadarLine = 34,

/**/

/// <summary>

/// 填充雷达图

/// </summary>

chChartTypeRadarLineFilled = 36,

/**/

/// <summary>

/// 制造雷达图

/// </summary>

chChartTypeRadarLineMarkers = 35,

/**/

/// <summary>

/// 平滑雷达图

/// </summary>

chChartTypeRadarSmoothLine = 37,

/**/

/// <summary>

/// 制造平滑雷达图

/// </summary>

chChartTypeRadarSmoothLineMarkers = 38,

/**/

/// <summary>

/// 线形散点图

/// </summary>

chChartTypeScatterLine = 25,

/**/

/// <summary>

/// 填充线形散点图

/// </summary>

chChartTypeScatterLineFilled = 26,

/**/

/// <summary>

/// 制造线形散点图

/// </summary>

chChartTypeScatterLineMarkers = 24,

/**/

/// <summary>

/// 制造散点图

/// </summary>

chChartTypeScatterMarkers = 21,

/**/

/// <summary>

/// 平滑散点图

/// </summary>

chChartTypeScatterSmoothLine = 23,

/**/

/// <summary>

/// 制造平滑散点图

/// </summary>

chChartTypeScatterSmoothLineMarkers = 22,

/**/

/// <summary>

/// 平滑线图

/// </summary>

chChartTypeSmoothLine = 12,

/**/

/// <summary>

/// 制造平滑线图

/// </summary>

chChartTypeSmoothLineMarkers = 13,

/**/

/// <summary>

/// 重叠平滑线图

/// </summary>

chChartTypeSmoothLineStacked = 14,

/**/

/// <summary>

/// 100%重叠平滑线图

/// </summary>

chChartTypeSmoothLineStacked100 = 16,

/**/

/// <summary>

/// 制造100%重叠平滑线图

/// </summary>

chChartTypeSmoothLineStacked100Markers = 17,

/**/

/// <summary>

/// 制造重叠平滑线图

/// </summary>

chChartTypeSmoothLineStackedMarkers = 15,

/**/

/// <summary>

/// 股价图

/// </summary>

chChartTypeStockHLC = 39,

/**/

/// <summary>

/// 股价图O型

/// </summary>

chChartTypeStockOHLC = 40

}

#endregion

#region 构造函数

public OWCChart11()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public OWCChart11(string SavePath, string SeriesName, string Title, int ChartType)

{

m_SavePath = SavePath;

m_SeriesName = SeriesName;

m_Title = Title;

m_Type = ChartType;

}

public OWCChart11(string SavePath, string SeriesName, string Title, int ChartType, string AxesXTitle, string AxesYTitle)

{

m_SavePath = SavePath;

m_SeriesName = SeriesName;

m_Title = Title;

m_AxesXTitle = AxesXTitle;

m_AxesYTitle = AxesYTitle;

m_Type = ChartType;

}

public OWCChart11(string SavePath, string SeriesName, string Title, int ChartType, string AxesXTitle, string AxesYTitle, int PicWidth, int PicHeight)

{

m_SavePath = SavePath;

m_SeriesName = SeriesName;

m_Title = Title;

m_AxesXTitle = AxesXTitle;

m_AxesYTitle = AxesYTitle;

m_PicWidth = PicWidth;

m_PicHeight = PicHeight;

m_Type = ChartType;

}

#endregion

public bool Create()

{

//声明对象

Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();

Microsoft.Office.Interop.Owc11.ChChart ThisChChart = ThisChart.Charts.Add(0);

Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);

//显示图例

ThisChChart.HasLegend = true;

//显示标题选项

ThisChChart.HasTitle = true;

ThisChChart.Title.Font.Name = "黑体";

ThisChChart.Title.Font.Size = 14;

ThisChChart.Title.Caption = m_Title;//from

//x,y轴说明

//x

ThisChChart.Axes[0].HasTitle = true;

ThisChChart.Axes[0].Title.Font.Name = "黑体";

ThisChChart.Axes[0].Title.Font.Size = 12;

ThisChChart.Axes[0].Title.Caption = m_AxesXTitle;

ThisChChart.Axes[1].HasTitle = true;

ThisChChart.Axes[1].Title.Font.Name = "黑体";

ThisChChart.Axes[1].Title.Font.Size = 12;

ThisChChart.Axes[1].Title.Caption = m_AxesYTitle;

//图表类型

ThisChChart.Type = (Microsoft.Office.Interop.Owc11.ChartChartTypeEnum)m_Type;

//            switch(m_Type)

//            {

//                case 0:

//                    ThisChChart.Type =(Microsoft.Office.Interop.Owc11.ChartChartTypeEnum) m_Type;// Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumn3D;//柱状图3D

//                    break;

//                case 1:

//                    ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBar3D;//横道图3D

//                    break;

//                case 2:

//                    ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine;//平滑曲线图

//                    break;

//                case 3:

//                    ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie;//圆饼图

//

//

//                    break;

//            }

//旋转

ThisChChart.Rotation = 360;

ThisChChart.Inclination = 10;

//背景颜色

ThisChChart.PlotArea.Interior.Color = "red";

//底座颜色

ThisChChart.PlotArea.Floor.Interior.Color = "green";

//ThisChChart.Overlap = 50;

//给定series的名字

ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), m_SeriesName);

//给定分类

ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), m_Category);

//给定值

ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), m_Value);

Microsoft.Office.Interop.Owc11.ChDataLabels dl = ThisChChart.SeriesCollection[0].DataLabelsCollection.Add();

dl.HasValue = true;

//dl.HasPercentage=true;

//导出图像文件

try

{

if (m_FileName == null || m_FileName == "")

{

m_FileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif";//生成图片名称

}

ThisChart.ExportPicture(m_SavePath + "\\" + m_FileName, "gif", m_PicWidth, m_PicHeight);

return true;

}

catch (Exception ee)

{

return false;

}

return false;

}

}

OWC11生成统计图案例的更多相关文章

  1. 使用C#和Excel进行报表开发(三)-生成统计图(Chart)

    有的Web项目选用Excel作为报表方案,在服务器端生成Excel文件,然后传送到客户端,由客户端进行打印.在国内的环境下,相对PDF方式,Excel的安装率应该比pdf阅读器的安装率要高,同时,微软 ...

  2. PHP中使用Jpgraph生成统计图

    Jpgraph是PHP图表类库,可以生成折线图.柱状图.大饼图等等统计图.如果你想使用PHP生成统计图来统计数据,使用它再方便不过啦. 如果说你要亲自使用GD库来写的话,那我只能膜拜大神啦(我不会哈哈 ...

  3. python制作简单excel统计报表3之将mysql数据库中的数据导入excel模板并生成统计图

    python制作简单excel统计报表3之将mysql数据库中的数据导入excel模板并生成统计图 # coding=utf-8 from openpyxl import load_workbook ...

  4. thinkphp3.2与phpexcel带图片生成 完美案例

    thinkphp3.2与phpexcel完美案例 // 导出exl public function look_down(){ $id = I('get.id'); $m = M ('offer_goo ...

  5. ddt 接口示范以及报告生成html案例

    1.数据构造获取我就不写了直接以test_data=[  ] 构造一个简单数据建模.实际你从哪里获取根据情况excel也好yaml也罢 2.用例套件处理,报告生成处理 import ddtimport ...

  6. js 动态生成表格案例

    <1>布局:一个table表格,表格分为两个部分,上面是thead表头,表头里面仅一行,有4列(th),   下面是tbody表格内容,要求tbody中的每一行都是用js动态创建的 < ...

  7. 告别.NET生成报表统计图的烦恼

    告别.NET生成报表统计图的烦恼 标签: 报表.netstatistics图形数据库文档 2009-10-09 12:00 635人阅读 评论(0) 收藏 举报  分类: .net程序设计(C#)(2 ...

  8. 【Java EE 学习 74 下】【数据采集系统第六天】【使用Jfreechart的统计图实现】【将JFreechart整合到项目中】

    之前说了JFreechart的基本使用方法,包括生成饼图.柱状统计图和折线统计图的方法.现在需要将其整合到数据采集系统中根据调查结果生成三种不同的统计图. 一.统计模型的分析和设计 实现统计图显示的流 ...

  9. 【Java EE 学习 74 上】【数据采集系统第六天】【使用Jfreechart的统计图实现】【Jfreechart的基本使用方法】

    之前已经实现了数据的采集,现在已经有了基本的数据,下一步就需要使用这些数据实现统计图的绘制了.这里使用Jfreechart实现这些统计图的绘制.首先看一下Jfreechart的基本用法,只有知道了它的 ...

随机推荐

  1. Unity3D流行的游戏开发人员构建高速检查站系统

    好友,大家好,欢迎关注我的博客.我是秦培,我的博客地址blog.csdn.net/qinyuanpei. 今天,我想分享的是,现在在移动平台上的检查点系统更受欢迎,机游戏如<愤慨的小鸟>. ...

  2. 采用xshell链路本地虚拟机Linux

    昨天想安装在自己的机器看Linux.而使用xshell通路.但是这花了很长的时间,于xshell结束所有的提示"Could not connect to '192.168.54.100' ( ...

  3. 十天学Linux内核之第七天---电源开和关时都发生了什么

    原文:十天学Linux内核之第七天---电源开和关时都发生了什么 说实话感觉自己快写不下去了,其一是有些勉强跟不上来,其二是感觉自己越写越差,刚开始可能是新鲜感以及很多读者的鼓励,现在就是想快点完成自 ...

  4. wikioi 1002 旁路

    意甲冠军:这个问题刚开始的问题,有错误的含义,原桥始建于一条直线.无论多么遥远. 思维:dfs寻求答案的第一个问题.然后做最小生成树,双方不能大桥将设置INF即可了.然后假设用到INF的边就加上0即可 ...

  5. 【转】细说Cookie

    阅读目录 开始 Cookie 概述 Cookie的写.读过程 使用Cookie保存复杂对象 Js中读写Cookie Cookie在Session中的应用 Cookie在身份验证中的应用 Cookie的 ...

  6. node.js高效操作mongodb

    node.js高效操作mongodb Mongoose库简而言之就是在node环境中操作MongoDB数据库的一种便捷的封装,一种对象模型工具,类似ORM,Mongoose将数据库中的数据转换为Jav ...

  7. 百度地图API详解之事件机制,function“闭包”解决for循环和监听器冲突的问题:

    原文:百度地图API详解之事件机制,function"闭包"解决for循环和监听器冲突的问题: 百度地图API详解之事件机制 2011年07月26日 星期二 下午 04:06 和D ...

  8. [ 单例、代理 & 通知 ]

    PS:手写单例.代理方法实现 & 通知的简单使用! [ 单例模式,代理设计模式,观察者模式! ] 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设 ...

  9. hbase ganglia监控配置

    hbase ganglia 显示器 hbase 构造 hadoop-metrics2-hbase.properties *.sink.ganglia.class=org.apache.hadoop.m ...

  10. 饼干怪兽和APT攻击

    APT攻击就像一个孩子,你通过各种方式窃取他们的大脑要拿出饼干,为了防止恶意攻击,过失作为母亲未能发现和防止饼干盗窃贼如.于她仅仅监视厨房椅子.衣柜门或烤箱门的开启.建立起有效防御目标攻击与APT攻击 ...