如何編寫asp.net中調(diào)用Office來制作3D統(tǒng)計(jì)圖的代碼-創(chuàng)新互聯(lián)

這篇文章主要講解了“如何編寫asp.net中調(diào)用Office來制作3D統(tǒng)計(jì)圖的代碼”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“如何編寫asp.net中調(diào)用Office來制作3D統(tǒng)計(jì)圖的代碼”吧!

成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、曲江網(wǎng)絡(luò)推廣、微信小程序、曲江網(wǎng)絡(luò)營銷、曲江企業(yè)策劃、曲江品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供曲江建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:muchs.cn

1、首先下載owc11 COM組件

/tupian/20230522/  在工程中添加 C:/Program Files/Common Files/Microsoft Shared/Web Components/11  文件下的owc11.dll引用

3、在工程中添加

using OWC11;

4、開始coding  舉例如下:

復(fù)制代碼 代碼如下:

   public class ChartFactory
{
public ChartFactory()
{
InitTypeMap();
//
// TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}
protected System.Web.UI.WebControls.Image imgHondaLineup;
private string[] chartCategoriesArr;
private string[] chartValuesArr;
private OWC11.ChartChartTypeEnum chartType =  OWC11.ChartChartTypeEnum.chChartTypeColumn3D;//默認(rèn)值
private static Hashtable chartMap = new Hashtable();
private static string chartTypeCh = "垂直柱狀圖" ;
private static string chartTitle = "";

private void InitTypeMap()
{
chartMap.Clear();
OWC11.ChartChartTypeEnum[] chartTypes = new OWC11.ChartChartTypeEnum[]{ ChartChartTypeEnum.chChartTypeColumnClustered,
ChartChartTypeEnum.chChartTypeColumn3D,
ChartChartTypeEnum.chChartTypeBarClustered,
ChartChartTypeEnum.chChartTypeBar3D,
ChartChartTypeEnum.chChartTypeArea,
ChartChartTypeEnum.chChartTypeArea3D,
ChartChartTypeEnum.chChartTypeDoughnut,
ChartChartTypeEnum.chChartTypeLineStacked,
ChartChartTypeEnum.chChartTypeLine3D,
ChartChartTypeEnum.chChartTypeLineMarkers,
ChartChartTypeEnum.chChartTypePie,
ChartChartTypeEnum.chChartTypePie3D,
   ChartChartTypeEnum.chChartTypeRadarSmoothLine,
ChartChartTypeEnum.chChartTypeSmoothLine};

string[] chartTypesCh = new string [] {"垂直柱狀統(tǒng)計(jì)圖","3D垂直柱狀統(tǒng)計(jì)圖","水平柱狀統(tǒng)計(jì)圖","3D水平柱狀統(tǒng)計(jì)圖","區(qū)域統(tǒng)計(jì)圖","3D區(qū)域統(tǒng)計(jì)圖","中空餅圖","折線統(tǒng)計(jì)圖","3D折線統(tǒng)計(jì)圖","折線帶點(diǎn)統(tǒng)計(jì)圖","餅圖","3D餅圖","網(wǎng)狀統(tǒng)計(jì)圖","弧線統(tǒng)計(jì)圖"};


   for(int i=0;i<chartTypes.Length;i++)
{
chartMap.Add(chartTypesCh[i],chartTypes[i]);
}
}
public ChartSpaceClass BuildCharts ()
{
string chartCategoriesStr = String.Join ("/t", chartCategoriesArr);
string chartValuesStr = String.Join ("/t", chartValuesArr);

OWC11.ChartSpaceClass       oChartSpace = new OWC11.ChartSpaceClass ();

// ------------------------------------------------------------------------
// Give pie and doughnut charts a legend on the bottom. For the rest of
// them let the control figure it out on its own.
// ------------------------------------------------------------------------

chartType = (ChartChartTypeEnum)chartMap[chartTypeCh];

if (chartType == ChartChartTypeEnum.chChartTypePie ||
chartType == ChartChartTypeEnum.chChartTypePie3D ||
chartType == ChartChartTypeEnum.chChartTypeDoughnut)
{
oChartSpace.HasChartSpaceLegend = true;
oChartSpace.ChartSpaceLegend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
}

oChartSpace.Border.Color = "blue";
oChartSpace.Charts.Add(0);
oChartSpace.Charts[0].HasTitle = true;
oChartSpace.Charts[0].Type = chartType;
oChartSpace.Charts[0].ChartDepth = 125;
oChartSpace.Charts[0].AspectRatio = 80;
oChartSpace.Charts[0].Title.Caption = chartTitle;
oChartSpace.Charts[0].Title.Font.Bold = true;

oChartSpace.Charts[0].SeriesCollection.Add(0);
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection.Add ();

// ------------------------------------------------------------------------
// If you're charting a pie or a variation thereof percentages make a lot
// more sense than values...
// ------------------------------------------------------------------------
   if (chartType == ChartChartTypeEnum.chChartTypePie ||
chartType == ChartChartTypeEnum.chChartTypePie3D ||
chartType == ChartChartTypeEnum.chChartTypeDoughnut)
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
}
// ------------------------------------------------------------------------
// Not so for other chart types where values have more meaning than
// percentages.
// ------------------------------------------------------------------------
else
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasPercentage = false;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].HasValue = true;
}

// ------------------------------------------------------------------------
// Plug your own visual bells and whistles here
// ------------------------------------------------------------------------
oChartSpace.Charts[0].SeriesCollection[0].Caption = String.Empty;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Name = "verdana";
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Font.Color = "red";
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionCenter;

if (chartType == ChartChartTypeEnum.chChartTypeBarClustered ||
chartType == ChartChartTypeEnum.chChartTypeBar3D ||
chartType == ChartChartTypeEnum.chChartTypeColumnClustered ||
chartType == ChartChartTypeEnum.chChartTypeColumn3D)
{
oChartSpace.Charts[0].SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;
}

oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr);


oChartSpace.Charts[0].SeriesCollection[0].SetData (OWC11.ChartDimensionsEnum.chDimValues,
Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValuesStr);

return oChartSpace;
}

#region  屬性設(shè)置
public string[] chartCategoriesArrValue
{
get
{
return chartCategoriesArr;
}
set
{
chartCategoriesArr = value;
}
}

public string[] chartValuesArrValue
{
get
{
return chartValuesArr;

   }
set
{
chartValuesArr = value;
}
}
public string chartTypeValue
{
get
{
return chartTypeCh;
}
set
{
chartTypeCh = value;
}
}
public string chartTitleValue
{
get
{
return chartTitle;
}
set
{
chartTitle = value;
}
}
#endregion
}

//調(diào)用   首先需要在頁面上放置一個(gè)Image來顯示產(chǎn)生的統(tǒng)計(jì)圖

public void ShowChart()
{

//初始化賦值
chartFactory.chartCategoriesArrValue = chartCategories;
chartFactory.chartValuesArrValue = chartValues;
chartFactory.chartTitleValue = chartTitle;
chartFactory.chartTypeValue = chartType;

OWC11.ChartSpaceClass oChartSpace = chartFactory.BuildCharts();
string path = Server.MapPath(".") + @"/images/Chart.jpeg";  //產(chǎn)生圖片并保存 頁可以是png gif圖片
oChartSpace.ExportPicture(path,"jpeg", 745, 500);
Image1.ImageUrl = path;  // 顯示統(tǒng)計(jì)圖
}

// 保存統(tǒng)計(jì)圖請參照上一篇文章

//由于每次生成的統(tǒng)計(jì)圖都會(huì)覆蓋原來的圖片所以有必要的話可以用日期加時(shí)間的方式來作為圖片的名字,但是這樣將會(huì)產(chǎn)生很多圖片需及時(shí)處理,如不需要只需取同名覆蓋原來圖片即可。


感謝各位的閱讀,以上就是“如何編寫asp.net中調(diào)用Office來制作3D統(tǒng)計(jì)圖的代碼”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對如何編寫asp.net中調(diào)用Office來制作3D統(tǒng)計(jì)圖的代碼這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

網(wǎng)頁標(biāo)題:如何編寫asp.net中調(diào)用Office來制作3D統(tǒng)計(jì)圖的代碼-創(chuàng)新互聯(lián)
標(biāo)題網(wǎng)址:http://muchs.cn/article36/deihsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、虛擬主機(jī)、全網(wǎng)營銷推廣、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司