(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. Linux内核导出符号宏定义EXPORT_SYMBOL源代码分析

    资源: <include/linux/moudule.h> --. #ifndef MODULE_SYMBOL_PREFIX #define MODULE_SYMBOL_PREFIX &q ...

  2. 设计模式——依赖倒置原则实例(PHP实现)

    <?php /** * 设计模式--依赖倒置原则实例 * Created by DannyWang * jue.wang@yulore.com * 2015-05-05 */ abstract ...

  3. SVN和Git的一些用法总结(转)

    转载请注明出处:http://www.codelast.com/ 以下都是比较基础的操作,高手们请绕道,不必浪费时间来看了. (A)SVN (1)查看日志提交的时候一般会写上注释,如果要查看提交日志, ...

  4. jvm对大对象分配内存的特殊处理(转)

    前段日子在和leader交流技术的时候,偶然听到jvm在分配内存空间给大对象时,如果young区空间不足会直接在old区切一块过去.对于这个结论很好奇,也比较怀疑,所以就上网搜了下,发现还真有这么回事 ...

  5. 第7章 桥接模式(Bridge Pattern)

    原文 第7章 桥接模式(Bridge Pattern) 定义: 在软件系统中,某些类型由于自身的逻辑,它具有两个或多个维度的变化,那么如何应对这种“多维度的变化”?如何利用面向对象的技术来使得该类型能 ...

  6. AspNetPager使用指南

    一.AspNetPager支持两种方式分页: 一种是PostBack方式分页, 一种是通过Url来实现分页以及Url重写功能 二.AspNetPager支持各种数据绑定控件GridView.DataG ...

  7. jquery.validate1.13

    jquery.validate新的写法(jquery.validate1.13.js) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  8. oracle_恢复流程图

    网上看到一个很好的数据恢复检查图片,共享给大家

  9. python_在windows下安装配置python开发环境及Ulipad开发工具

    最近开始学习Python,在网上寻找一下比较好的IDE.因为以前用C#做开发的,用Visual Studio作为IDE,鉴于用惯了VS这么强大的IDE,所以对IDE有一定的依赖性. Python的ID ...

  10. 大话设计模式C++达到-文章16章-国家模式

    一.UML画画 二.概念 状态模式(State):当一个对象的内在状态改变时同意改变其行为.这个对象看起来像是改变了其类. 三.说明 以下是来自书本和网络的对状态模式的定义和分析: (1)状态模式同意 ...