跳到主要內容

利用OWC畫統計圖

VB超人告訴我,可以用Microsoft Office Web Components(OWC)畫統計圖,比起其他的Asp.net統計圖,又多了些互動功能(在用戶端有裝Office的情況)。

下載:Office 2003 增益集:Office 網頁元件
參考:
The Microsoft Office Web Components
ASP.NET Server-Side Charting with OWC11

在Asp.Net 2.0的開發模式中,只要放在bin下就算加入參考,所以鳥毅先開一個檔案系統的網站


再把從codeproject下載的專案裏的bin目錄複製過來,省得自己找dll檔,在專案總管按下重新整理即可


把Alvin Bruney寫的這段Code複製到Page_Load,變成
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. //First create a ChartSpace object to hold the chart
  4. ChartSpace objCSpace = new ChartSpaceClass();
  5. //Add a chart and provide a type
  6. ChChart objChart = objCSpace.Charts.Add(0);
  7. objChart.Type = ChartChartTypeEnum.chChartTypePie3D;
  8. //add chart titles and legend
  9. objChart.HasTitle = true;
  10. objChart.Title.Caption = "ASP.NET Charts";
  11. objChart.HasLegend = true;
  12. objChart.Legend.Border.DashStyle = OWC11.ChartLineDashStyleEnum.chLineDash;
  13. objChart.Legend.Position = OWC11.ChartLegendPositionEnum.chLegendPositionRight;
  14. //Populate with contrived data
  15. string strCategory = "Cars, Trucks, Vans, Big Rigs, Motorcycles, Mopeds";
  16. string strValue = "13,12,31,43,23,15";
  17. //Add a series to the chart's series collection
  18. objChart.SeriesCollection.Add(0);
  19. //load the category and value data
  20. objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
  21. (int)ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);
  22. objChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
  23. (int)ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
  24. //show the chart on the client
  25. Response.ContentType = "image/gif";
  26. Response.BinaryWrite((byte[])objCSpace.GetPicture("gif", 500, 400));
  27. Response.End();
  28. }

執行後結果:


詳細的物件模型請參考:HOW TO:尋找 Office Web 元件 (OWC) 程式設計說明文件與範例

說真的,這種COM物件的繪圖方式類似ProEssentials得一個個指定,我還是比較喜歡原生支援.Net的Crystal Reports

留言

這個網誌中的熱門文章

DBeaver 介面語言

DBeaver是我個人頗常用的一套跨平台Database管理工具,最近升級後發現Windows版本居然變成簡體中文,而且無法切換為英文。

自然人憑證讀卡機驅動程式

鳥毅用的是第一代的自然人憑證讀卡機,EZ100PU(後來有同事買EZmini可以讀SIM卡似乎更好),每年報稅時用一次。 本來只是要申請些政府業務,一時之間找不到光碟,沒想到在 驅動程式下載 居然看到Linux和Mac的驅動程式,剩下的就是政府單位的網頁和程式應該改版了吧!!!

如何將較高版本SQL Server複製到低版本SQL Server (降級為舊版)並保留權限及資料庫圖表

一般若是要將SQL Server裡的Database轉往其他Server時,最簡單的方式就是備份(Backup)後再還原(Restore),或者是䣃離(detach)後附加(attach)。 但是很不幸地,若是由較低版本(e.g. 2008)到較高版本(e.g. 2012)要怎麼辦呢?