統(tǒng)計圖表樣本_第1頁
統(tǒng)計圖表樣本_第2頁
統(tǒng)計圖表樣本_第3頁
統(tǒng)計圖表樣本_第4頁
統(tǒng)計圖表樣本_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

效果圖:

手把手教程:原理:OWC是Office

Web

Compent縮寫,即MicrosoftOffice

Web組件,它為在Web中繪制圖形提供了靈活同步也是最基本機制。在一種intranet環(huán)境中,如果可以假設客戶機上存在特定瀏覽器和某些功能強大軟件(如IE6和Office

/XP/),那么就有能力運用Office

Web組件提供一種交互式圖形開發(fā)環(huán)境。這種模式下,客戶端工作站將在整個任務中分擔很大比重。理論上說Excel能做圖都可以通過OWC畫。第一步:

右鍵點擊網(wǎng)站根目錄引用。如圖所示:

第二步:

點擊“添加引用”后彈出一種窗口,添加OWC引用。如圖所示:

點“擬定”。第三步:

代碼中引用Microsoft.Office.Interop.Owc11。所有代碼

后臺代碼:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;

//添加數(shù)據(jù)操作引用

usingMicrosoft.Office.Interop.Owc11;//添加Office組件引用publicpartialclassOWCdrawing:System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

//連接數(shù)據(jù)庫并獲取特定字符串

stringstrSeriesName="圖例1";

stringConnectString="Server=(local);DataBase=web;Uid=sa;Pwd=sa";

stringSql="SELECTmonth,AllcountFROMChart";

SqlConnectionmyConn=newSqlConnection(ConnectString);

myConn.Open();

SqlDataAdapterDa=newSqlDataAdapter(Sql,myConn);

DataSetds=newDataSet();

Da.Fill(ds);//存儲月

string[]MonNum=newstring[12];

//存儲數(shù)據(jù)

string[]MonCount=newstring[12];

//為數(shù)組賦值

for(inti=0;i<ds.Tables[0].Rows.Count;i++)

{

MonNum[i]=ds.Tables[0].Rows[i][0].ToString();

MonCount[i]=ds.Tables[0].Rows[i][1].ToString();

}

//為x軸指定特定字符串,以便顯示數(shù)據(jù)

stringstrXdata=String.Empty;

foreach(stringstrDatainMonNum)

{

strXdata+=strData+"\t";

}

stringstrYdata=String.Empty;

//為y軸指定特定字符串,以便與x軸相相應

foreach(stringstrValueinMonCount)

{

strYdata+=strValue+"\t";

}

//創(chuàng)立ChartSpace對象來放置圖表

ChartSpacelaySpace=newChartSpaceClass();

//在ChartSpace對象中添加圖表

ChChartInsertChart=laySpace.Charts.Add(0);

//指定繪制圖表類型。類型可以通過OWC.ChartChartTypeEnum枚舉值得到

//InsertChart.Type=ChartChartTypeEnum.chChartTypeLine;//折線圖

//InsertChart.Type=ChartChartTypeEnum.chChartTypeArea;//面積圖

//InsertChart.Type=ChartChartTypeEnum.chChartTypeBarClustered;//條形圖

InsertChart.Type=ChartChartTypeEnum.chChartTypeColumnClustered;//柱形圖

//指定圖表與否需要圖例標注

InsertChart.HasLegend=false;

InsertChart.HasTitle=true;//為圖表添加標題

InsertChart.Title.Caption="清清月兒每月花銷流水賬";//標題名稱

//為x,y軸添加圖示闡明

InsertChart.Axes[0].HasTitle=true;

InsertChart.Axes[0].Title.Caption="";//月份

InsertChart.Axes[1].HasTitle=true;

InsertChart.Axes[1].Scaling.SplitMinimum=200;

InsertChart.Axes[1].Title.Caption="數(shù)量";

//添加一種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);

//輸出文獻.

stringstrAbsolutePath=(Server.MapPath("."))+"\\ShowData.gif";

laySpace.ExportPicture(strAbsolutePath,"GIF",400,250);

//創(chuàng)立GIF文獻相對途徑.

stringstrRelativePath="./ShowData.gif";

//把圖片添加到placeholder中,并在頁面上顯示

stringstrImageTag="<IMGSRC='"+strRelativePath+"'/>";

this.PlaceHolder1.Controls.Add(newLiteralControl(strImageTag));

}

}前臺代碼:

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="OWCdrawing.aspx.cs"Inherits="OWCdrawing"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"""><htmlxmlns="">

<headrunat="server">

<title>清清月兒</title>

</head>

<body>

<formid="form1"runat="server">

<divstyle="text-align:left">

<tablestyle="width:600px">

<tr>

<tdcolspan="3"style="height:20px">

<strong>怎么樣在ASP.NET2.0中使用OWC組件畫圖</strong></td>

</tr>

<tr>

<tdcolspan="3"rowspan="2"style="height:21px">

<asp:PlaceHolderID="PlaceHolder1"runat="server"></asp:PlaceHolder>

</td>

</tr>

<tr>

</tr>

</table>

</div>

</form>

</body>

</html>數(shù)據(jù)庫SQL腳本:

USE[web]

GO

/******對象:

Table[dbo].[Chart]

腳本日期:03/27/22:26:00******/

SETANSI_NULLSON

GO

SETQUOTED_IDENTIFIERON

GO

CREATETABLE[dbo].[Chart](

[id][int]IDENTITY(1,1)NOTNULL,

[month][smallint]NULL,

[Allcount][int]NULL

)ON[PRIMARY]在數(shù)據(jù)庫建好表后來要自己手動假想有12條數(shù)據(jù),手動添加,最后成果類似下圖:

后臺程序闡明:

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論