使用owc11组件画柱形图、折线图、面积图等

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为图片名称

你可能感兴趣的:(Date,String,Class,扩展)