推薦:ASP.NET 2.0移動開發入門的使用樣式每個ASP.NET移動控件都提供了若干樣式屬性,使用這些屬性可以自定義控件的呈現方式。當然你也可以使用StyleSheet控件來定義樣式信息,然后在同一個頁面的不同控件上應用StyleSheet控件定義的樣式信息。我們在前面已經提及到你不但可以將樣式應用到不同的控件
ASP.NET 2.0中,要顯示圖型的話,可以用MS office 2003的OWC組件,可以十分方便地看到圖表。在工程中,首先添加microsoft office web components 11.0的引用就可以了,然后要using Microsoft.Office.Interop.Owc11;
1、生成柱狀圖
//創建X坐標的值,表示月份 int[] Month = new int[3] { 1, 2, 3 }; //創建Y坐標的值,表示銷售額 double[] Count = new double[3] { 120,240,220}; //創建圖表空間 ChartSpace mychartSpace = new ChartSpace(); //在圖表空間內添加一個圖表對象 ChChart mychart = mychartSpace.Charts.Add(0); //設置圖表類型,本例使用柱形 mychart.Type = ChartChartTypeEnum.chChartTypeColumnClustered; //設置圖表的一些屬性 //是否需要圖例 mychart.HasLegend = true; //是否需要主題 mychart.HasTitle = true; //主題內容 mychart.Title.Caption = "一季度總結"; //設置x,y坐標 mychart.Axes[0].HasTitle = true; mychart.Axes[0].Title.Caption = "月份"; mychart.Axes[1].HasTitle = true; mychart.Axes[1].Title.Caption = "銷量"; //添加三個圖表塊 mychart.SeriesCollection.Add(0); mychart.SeriesCollection.Add(0); mychart.SeriesCollection.Add(0); //設置圖表塊的屬性 //標題 mychart.SeriesCollection[0].Caption = "一月份"; //X坐標的值屬性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[0]); //y坐標的值屬性 mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[0]); //第二個塊 mychart.SeriesCollection[1].Caption = "二月份"; //X坐標的值屬性 mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[1]); //y坐標的值屬性 mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Count[1]); //第三個塊 mychart.SeriesCollection[2].Caption = "三月份"; //X坐標的值屬性 mychart.SeriesCollection[2].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, Month[2]); //y坐標的值屬性 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) { //創建X坐標的值,表示月份 int[] Month ={ 1, 2, 3 }; //創建Y坐標的值,表示銷售額 double[] Count ={ 120, 240, 220 }; string strDataName = ""; string strData = ""; //創建圖表空間 ChartSpace mychartSpace = new ChartSpace(); //在圖表空間內添加一個圖表對象 ChChart mychart = mychartSpace.Charts.Add(0); //設置每塊餅的數據 for (int i = 0; i < Count.Length; i ) { strDataName = Month[i] "/t"; strData = Count[i].ToString() "/t"; } //設置圖表類型,本例使用柱形 mychart.Type = ChartChartTypeEnum.chChartTypePie; //設置圖表的一些屬性 //是否需要圖例 mychart.HasLegend = true; //是否需要主題 mychart.HasTitle = true; //主題內容 mychart.Title.Caption = "一季度總結"; //添加圖表塊 mychart.SeriesCollection.Add(0); //設置圖表塊的屬性 //分類屬性 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高級應用:簡化ANF自定義控件初始化過程Attribute應用,簡化ANF自定義控件初始化過程 研究ANF的源碼,讓我獲益良多。其中很多思想,都是非常值得學習的。其中換膚的方式,寶玉已經介紹過了,《Asp.Net Forums2.0深入分析》之 Asp.Net Forums是如何實現代碼分離和換皮膚的。不過,當一個自定義控件
新聞熱點
疑難解答
圖片精選