ASP.NET 2.0中使用OWC生成圖表_.Net教程
推薦:ASP.NET 2.0移動(dòng)開(kāi)發(fā)入門(mén)的使用樣式每個(gè)ASP.NET移動(dòng)控件都提供了若干樣式屬性,使用這些屬性可以自定義控件的呈現(xiàn)方式。當(dāng)然你也可以使用StyleSheet控件來(lái)定義樣式信息,然后在同一個(gè)頁(yè)面的不同控件上應(yīng)用StyleSheet控件定義的樣式信息。我們?cè)谇懊嬉呀?jīng)提及到你不但可以將樣式應(yīng)用到不同的控件
ASP.NET 2.0中,要顯示圖型的話,可以用MS office 2003的OWC組件,可以十分方便地看到圖表。在工程中,首先添加microsoft office web components 11.0的引用就可以了,然后要using Microsoft.Office.Interop.Owc11;
1、生成柱狀圖
//創(chuàng)建X坐標(biāo)的值,表示月份 int[] Month = new int[3] { 1, 2, 3 }; //創(chuàng)建Y坐標(biāo)的值,表示銷(xiāo)售額 double[] Count = new double[3] { 120,240,220}; //創(chuàng)建圖表空間 ChartSpace mychartSpace = new ChartSpace(); //在圖表空間內(nèi)添加一個(gè)圖表對(duì)象 ChChart mychart = mychartSpace.Charts.Add(0); //設(shè)置圖表類(lèi)型,本例使用柱形 mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered; //設(shè)置圖表的一些屬性 //是否需要圖例 mychart.HasLegend = true; //是否需要主題 mychart.HasTitle = true; //主題內(nèi)容 mychart.Title.Caption = "一季度總結(jié)"; //設(shè)置x,y坐標(biāo) mychart.Axes[0].HasTitle = true; mychart.Axes[0].Title.Caption = "月份"; mychart.Axes[1].HasTitle = true; mychart.Axes[1].Title.Caption = "銷(xiāo)量"; //添加三個(gè)圖表塊 mychart.SeriesCollection.Add(0); mychart.SeriesCollection.Add(0); mychart.SeriesCollection.Add(0); //設(shè)置圖表塊的屬性 //標(biāo)題 mychart.SeriesCollection[0].Caption = "一月份"; //X坐標(biāo)的值屬性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[0]); //y坐標(biāo)的值屬性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[0]); //第二個(gè)塊 mychart.SeriesCollection[1].Caption = "二月份"; //X坐標(biāo)的值屬性 mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[1]); //y坐標(biāo)的值屬性 mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[1]); //第三個(gè)塊 mychart.SeriesCollection[2].Caption = "三月份"; //X坐標(biāo)的值屬性 mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[2]); //y坐標(biāo)的值屬性 mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[2]); //生成圖片 mychartSpace.ExportPicture(Server.MapPath(".") @"\test.jpg", "jpg", 500, 450); //加載圖片 Image1.ImageUrl = Server.MapPath(".") @"\test.jpg"; }
2、生成餅狀圖
protected void Page_Load(object sender, EventArgs e) { //創(chuàng)建X坐標(biāo)的值,表示月份 int[] Month ={ 1, 2, 3 }; //創(chuàng)建Y坐標(biāo)的值,表示銷(xiāo)售額 double[] Count ={ 120, 240, 220 }; string strDataName = ""; string strData = ""; //創(chuàng)建圖表空間 ChartSpace mychartSpace = new ChartSpace(); //在圖表空間內(nèi)添加一個(gè)圖表對(duì)象 ChChart mychart = mychartSpace.Charts.Add(0); //設(shè)置每塊餅的數(shù)據(jù) for (int i = 0; i < Count.Length; i ) { strDataName = Month[i] "\t"; strData = Count[i].ToString() "\t"; } //設(shè)置圖表類(lèi)型,本例使用柱形 mychart.Type = ChartChartTypeEnum.chChartTypePie; //設(shè)置圖表的一些屬性 //是否需要圖例 mychart.HasLegend = true; //是否需要主題 mychart.HasTitle = true; //主題內(nèi)容 mychart.Title.Caption = "一季度總結(jié)"; //添加圖表塊 mychart.SeriesCollection.Add(0); //設(shè)置圖表塊的屬性 //分類(lèi)屬性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName); //值屬性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strData); //顯示百分比 ChDataLabels mytb= mychart.SeriesCollection[0].DataLabelsCollection.Add(); mytb.HasPercentage = true; //生成圖片 mychartSpace.ExportPicture(Server.MapPath(".") @"\test.gif", "gif", 500, 450); //加載圖片 Image1.ImageUrl = Server.MapPath(".") @"\test.gif"; }
分享:Attribute高級(jí)應(yīng)用:簡(jiǎn)化ANF自定義控件初始化過(guò)程Attribute應(yīng)用,簡(jiǎn)化ANF自定義控件初始化過(guò)程 研究ANF的源碼,讓我獲益良多。其中很多思想,都是非常值得學(xué)習(xí)的。其中換膚的方式,寶玉已經(jīng)介紹過(guò)了,《Asp.Net Forums2.0深入分析》之 Asp.Net Forums是如何實(shí)現(xiàn)代碼分離和換皮膚的。不過(guò),當(dāng)一個(gè)自定義控件
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見(jiàn)代碼存在的偽造IP問(wèn)題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(kù)(連接字符串的配置及獲取)
- asp.net頁(yè)面?zhèn)髦禍y(cè)試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過(guò)程實(shí)現(xiàn)分頁(yè)示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- 采用Native 引導(dǎo)方式的.Net加密保護(hù)
- 淺談ASP.NET中使用AJAX的簡(jiǎn)單方法
- .NET Framework 3.5 SP1正式版
- 為GridView新增記錄的功能
- 如何在Asp.net中使用HtmlArea編輯器
- System.Data.SqlClient.SqlException: 無(wú)法打開(kāi)登錄所請(qǐng)求的數(shù)據(jù)庫(kù)
- 總結(jié).NET開(kāi)發(fā)中ADO.NET的應(yīng)用
- 解析.Net基礎(chǔ):C#中對(duì)DatagridView部分常用操作
- c#.net函數(shù)列表
- String.Empty、NULL、“”的不同之處
- 相關(guān)鏈接:
- 教程說(shuō)明:
.Net教程-ASP.NET 2.0中使用OWC生成圖表
。