1, download OWC11 COM components
http://www.microsoft.com/downloads/details.aspx?familyid=7287252c-402e-4f72-97a5-e0fd290d4b76&displaylang=en
2, register OWC11
Install the downloaded file, then add the COM component of Microsoft Office Web Components 11.0 in the project
3, add it 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, ChartChartTypeEnum.chChartTypeRadarSmoothLine, ChartChartTypeEnum.chChartTypeSmoothLine}; string [] chartTypesCh = new string [] { "vertical bar graph" "3D vertical column statistics " Folding Point Statistics "," Pie Diagram "," 3D Pie Diagram "," Net Chart "," Arc Chart "}; for (INT i = 0;
Chartmap.add (charttypesch [i], charttypes [i]);
}
}
Public ChartspaceClass Buildcharts () {String ChartcategoriesStr = String.Join ("/ T", Chartcategoriesarr); String ChartValuesStr = String.join ("/ T", ChartValerr);
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 type where values have more meaning Than // percentages. // ------------- -------------------------------------------------- --------- else {OchartSpace.Charts [0] .seriescollection [0] .datalabelscollection [0] .haspercentage = false; OchartSpace.Charts [0] .seriescoll ECTION [0] .datalabelscollection [0] .haasvalue = true;} // ---------------------------------- --------------------------------------- // Plug Your OWN Visual Bells and whistles here / / --------------------------------------------------- ----------------------- OchartSpace.Charts [0] .seriescollection [0] .caption = string.empty; OchartSpace.Charts [0] .seriescollection [ 0] .datarabelscollection [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.CHARTSPECIALDATASOURESENUM.CHDATALITERAL), CHARTVALUESSTR);
Return Ochartspace;}
#REGON attribute set 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;}} #ENDREGON}
// Call first needs to place an image on the page to display the generated chart
Public void showchart () {
// Initialize assignment chartFactory.chartCategoriesArrValue = chartCategories; chartFactory.chartValuesArrValue = chartValues; chartFactory.chartTitleValue = chartTitle; chartFactory.chartTypeValue = chartType; 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
// Since each generated chart will overwrite the original picture, you can use the date to add time as the name, but this will have a lot of pictures to be handled in time. If you don't need to take the same name override It turns out that you can.