ASP.NET calls Office to make 3D chart

xiaoxiao2021-03-06  67

1, first download OWC11 COM components

[click to download]

2, register OWC11

Add c: / program files / common files / microsoft shared / web component / 11 files below 3, added in the project

Using OWC11;

4. Starting Coding is as follows:

public class ChartFactory {public ChartFactory () {InitTypeMap (); // // TODO: Add constructor logic //} protected System.Web.UI.WebControls.Image imgHondaLineup herein; private string [] chartCategoriesArr; private string [ ] chartValuesArr; private OWC11.ChartChartTypeEnum chartType = OWC11.ChartChartTypeEnum.chChartTypeColumn3D; // default private static Hashtable chartMap = new Hashtable (); private static string chartTypeCh = "vertical histogram"; 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,

String [] charttypesch = new string [] {"Vertical Column Statistics", "3D Vertical Column Statistics", "Horizontal Column Statistics", "3D Horizontal Column Statistics", "Regional Statistics", "3D Regional Statistics图 " Line statistics "};

For (int i = 0; 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 first out 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] .hartitle = true; OchartSpace.Charts [0] .Type = charttype; OchartSpace.Charts [0] .ChartDepth = 125; OchartSpace.Charts [0] .aspectratiotio = 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 variation theref percentages make a lot // more sense tour ... / / -------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------

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] .haasvalue = 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] .haasvalue = true;} // ---------------------------------------------------------------------------- -------------------------------------------------- ---- // Plug Your OWN Visual Bells and whistles Here // ---------------------------------- -------------------------------------- Ochartspace.Charts [0] .serie sCollection [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;}

#REGON attribute set public string [] ChartcategoriesarrValue {get {return chartcategoriesarr;} set {chartcategoriesarr = value;}}

Public string [] ChartvaluesarrValue {Get {Return ChartValer

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

// Call first needs to place an image on the page to display the generated chart

Public void showchart () {

// Initialization assignment chartfactory.ChartcategoriesarrValue = chartcategories; chartfactory.ChartValeSarrValue = chartvalues; chartfactory.CharttitiValue = Charttitle; ChartFactory.ChartTyPeValue = charType;

OWC11.CHARTSPACECLASS OCHARTSPACE = chartfactory.buildcharts (); string path = server.mappath (".") @ "/ Images / chart.jpeg"; // Generate a picture and save the page can be a PNG GIF picture OchartSpace.exportPicture (Path " , "JPEG", 745, 500); Image1.imageURL = path; // Display statistics}

// Save statistics, please refer to the previous article

//

转载请注明原文地址:https://www.9cbs.com/read-110454.html

New Post(0)