使用owc11组件画柱形图、折线图、面积图等
2009-09-27 10:43
302 查看
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.Office.Interop.Owc11; using System.Collections.Generic; using System.Collections; namespace Owc.Web.Common { /// <summary> /// OWCdrawing 的摘要说明 /// </summary> public class OWCdrawing { public OWCdrawing() { // // TODO: 在此处添加构造函数逻辑 // } private static string strSeriesName = "图例1"; public static string title;//标题名称 public static string xCaption;//X轴说明 public static string yCaption;//Y轴说明 public static string strAbsolutePath;//图片物理路径 public static string date; public static string Drawing(System.Collections.Hashtable ht, ChartChartTypeEnum value, string imgName) { int imgHight = 300; int count = ht.Count; string[] xNum = new string[count]; //存放数据 string[] yNum = new string[count]; int i = 0; //为数组赋值 foreach (DictionaryEntry de in ht) { string []temp = de.Value.ToString().Split(','); xNum[i] = temp[0]; yNum[i] = temp[1]; i++; } //为x轴指定特定字符串,以便显示数据 string strXdata = String.Empty; foreach (string strData in xNum) { strXdata += strData + "/t"; } string strYdata = String.Empty; //为y轴指定特定的字符串,以便与x轴相对应 foreach (string strValue in yNum) { strYdata += strValue + "/t"; } //创建ChartSpace对象来放置图表 ChartSpace laySpace = new ChartSpaceClass(); //在ChartSpace对象中添加图表 ChChart InsertChart = laySpace.Charts.Add(0); //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到 //InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图 //InsertChart.Type = ChartChartTypeEnum.chChartTypeArea;//面积图 //InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;//纵向柱形图 //InsertChart.Type = ChartChartTypeEnum.chChartTypeBarClustered;//横向柱形图 //InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered3D;//纵向3D柱形图 //InsertChart.Type = ChartChartTypeEnum.chChartTypeBarClustered3D; //为了数据量太大引起的图表样式的改变,这里规定数据超过10条后保存为横向柱形图 if (ht.Count > 10) { if (value.ToString() != "chChartTypeBarClustered3D" && value.ToString() != "chChartTypeBarClustered") { value = ChartChartTypeEnum.chChartTypeBarClustered; } imgHight = ht.Count * 40;//显示的图片高度根据数据条数扩展 } InsertChart.Type = value; //指定图表是否需要图例标注 InsertChart.HasLegend = false; InsertChart.HasTitle = true;//为图表添加标题 InsertChart.Title.Caption = title;//标题名称 //为x,y轴添加图示说明 InsertChart.Axes[0].HasTitle = true; InsertChart.Axes[0].Title.Caption = xCaption;//x轴说明 InsertChart.Axes[1].HasTitle = true; //InsertChart.Axes[1].Scaling.SplitMinimum = 200; InsertChart.Axes[1].Title.Caption = yCaption;//y轴说明 //添加一个series系列 InsertChart.SeriesCollection.Add(0); //给定series系列的名字 InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName); //给定分类 InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata); //给定值 InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata); //输出文件. laySpace.ExportPicture(strAbsolutePath, "GIF", 951, imgHight); //获取创建GIF文件的相对路径. string strRelativePath = "../Record/ReportImage/" + imgName; //把图片添加到placeholder中,并在页面上显示 string strImageTag = "<IMG SRC="" + strRelativePath + "" mce_SRC="" + strRelativePath + ""/>"; return strImageTag; } } }
Drawing(System.Collections.Hashtable ht, ChartChartTypeEnum value, string imgName)
说明:这里以hashtable作为图表的数据源,存放的方式为:key,"value,value",ChartChartTypeEnum value为页面给用户选择的图标呈现方式(折线图、面积图等),string imgName为图片名称
相关文章推荐
- asp.net 使用owc组件画图(折线图 面积图 柱状图等)
- C# WinForm开发系列之c# 通过.net自带的chart控件绘制饼图,柱形图和折线图的基础使用和扩展
- 在使用axSpreadSheet时OWC11 组件初始化错误的解决
- C# WinForm开发系列之c# 通过.net自带的chart控件绘制饼图,柱形图和折线图的基础使用和扩展
- 在C#中使用owc11 画折线图 .
- 使用JFreeCharts画一些折线图、柱形图、饼图
- 在C#中使用owc11 画折线图 .
- C# WinForm开发系列之c# 通过.net自带的chart控件绘制饼图,柱形图和折线图的基础使用和扩展
- MVC 通过继承HandleErrorAttribute,使用log4net或ELMAH组件记录异常等
- 使用映像劫持技术简易替换Windows组件
- BroadcastReceiver组件的使用
- 新闻类App使用的组件
- Regasm组件注册工具使用方法
- element 组件使用小教程集合(element1.3.6)
- Android组件之Service学习(1)两种使用方式与生命周期
- 如何制作Vuejs组件,并且在项目中使用
- 在rails 4 中 使用 CSV 组件来 把csv文件导入到数据库
- Flex List组件的使用
- Android组件的使用:Menu
- 网站前端_EasyUI.基础入门.0005.使用EasyUI Accordion组件的最佳姿势?