Use C # To draw a chart (pie chart line chart)

Source: Internet
Author: User

Public placeholder placeholder1; // controls for displaying images

The category names of each image are as follows:

Picturetype Graphic Type 5 chcharttypebarclustered clustered bar chart 0 null

Picturetype Graphic Type 7 chcharttypebarclustered3d 3D clustered bar chart 0 null

Picturetype Graphic Type 6 chcharttypebarstacked Stacked bar chart 0 null

Picturetype Graphic Type 8 chcharttypebarstacked3d Stacked bar chart 0 null

Picturetype Graphic Type 1 chcharttypecolumnclustered clustered column type 0 null

Picturetype Graphic Type 3 chcharttypecolumnclustered3d 3D clustered column type 0 null

Picturetype Graphic Type 2 chcharttypecolumnstacked Stacked column Chart 1 null

Picturetype Graphic Type 4 chcharttypecolumnstacked3d Stacked column limit 0 null

Picturetype Graphic Type 13 chcharttypeline line chart 0 null

Picturetype graph type 15 chcharttypelinemarkers data point line chart 0 null

Picturetype Graphic Type 14 chcharttypelinestacked stacked line chart 0 null

Picturetype Graphic Type 16 chcharttypelinestackedmarkers stacked data point line chart 0 null

Picturetype Graphic Type 17 chcharttypepie pie chart 1 null

Picturetype Graphic Type 19 chcharttypepie3d 3D pie chart 0 null

Picturetype graphic type 18 chcharttypepieexploded separated pie chart 0 null

Picturetype Graphic Type 20 chcharttypepieexploded3d separated 3D pie chart 0 null

Picturetype Graphic Type 9 chcharttypesmoothline smoothing line chart 0 null

Picturetype Graphic Type 10 chcharttypesmoothlinemarkers data point smoothing line chart 0 null

Picturetype Graphic Type 11 chcharttypesmoothlinestacked stacked smoothing line chart 0 null

Picturetype Graphic Type 12 chcharttypesmoothlinestackedmarkers stacked Data Smoothing Line chart 0 null

The image retrieval method is as follows:

/// </Summary> /// <Param name = "dbdtviewwrk"> transmitted data </param> /// <Param name = "strabsolutepath"> absolute path </ param> /// <Param name = "strrelativepath"> relative path </param> /// <Param name = "charttype"> Format of the graph to be drawn (pie chart or line chart)) </param> // <Param name = "strtitle"> statistical name </param> Public void painttoimage (datatable dbdtviewwrk, string strabsolutepath, string strrelativepath, character charttype, string strtitle) {string STRs Eriesname = "legend"; // stores the project string [] itemsname = new string [dbdtviewwrk. rows. count]; // string [] itemscount = new string [dbdtviewwrk. rows. count]; // The unit of scale int iunit = 1; // The maximum value int imaxvalue = 0; string strxdata = string. empty; string strydata = string. empty; // assign a value to the array for (INT I = 0; I <dbdtviewwrk. rows. count; I ++) {itemsname [I] = dbdtviewwrk. rows [I] [0]. tostring (); // field name to be counted itemscount [I] = dbdtvi Ewwrk. rows [I] [5]. tostring (); // field data to be calculated} // specify a specific string for the X axis to display data // string strxdata = string. empty; foreach (string strdata in itemsname) {strxdata + = strdata + "\ t" ;}// string strydata = string. empty; // specify a specific string for the Y axis to correspond to the X axis in foreach (string strvalue in itemscount) {strydata + = strvalue + "\ t"; if (Int. parse (strvalue)> imaxvalue) {imaxvalue = int. parse (strvalue) ;}}if (imaxvalue> 20) {iunit = Imaxvalue/10;} // create a chartspace object to place the chart chartspace layspace = new chartspaceclass (); // Add the chart chchart insertchart = layspace to the chartspace object. charts. add (0); // base color insertchart. plotarea. interior. color = "white"; // specify the chart type. You can use owc. chartcharttypeenum enumeration is worth accessing insertchart. type = charttype; // column chart // specifies whether the legend is required to indicate insertchart. haslegend = true; insertchart. barwidth = 0; insertchart. legend. position = chartlegendpositionenum. chlegendpositionbottom; insertchart. hastitle = true; // Add the title insertchart for the chart. title. caption = strtitle; // The title name. // If (charttype. tostring (). indexof ("charttypepie") =-1) {insertchart. axes [0]. font. size = 11; // the X axis of insertchart. axes [1]. font. size = 11; // y axis insertchart. legend. font. size = 11; insertchart. axes [0]. hastitle = true; insertchart. axes [0]. title. caption = ""; // insertchart of the month. axes [1]. hastitle = true; // insertchart. axes [1]. scaling. splitminimum = 200; insertchart. axes [1]. title. caption = "quantity"; insertchart. axes [1]. majorunit = iunit; // set the scale unit to insertchart. axes [1]. scaling. minimum = 0; // min scale = 0} // Add Add a series insertchart. seriescollection. add (0); // specifies the name of the Series, insertchart. seriescollection [0]. setdata (chartdimensionsenum. chdimseriesnames, + (INT) chartspecialperformancesenum. chdataliteral, strseriesname); // you can specify strxdata = strxdata. substring (0, strxdata. length-1); insertchart. seriescollection [0]. setdata (chartdimensionsenum. chdimcategories, + (INT) chartspecialperformancesenum. chdataliteral, strx Data); // specify strydata = strydata. substring (0, strydata. length-1); insertchart. seriescollection [0]. setdata (chartdimensionsenum. chdimvalues, (INT) chartspecialperformancesenum. chdataliteral, strydata); // Add the label chdatalabels DLS = insertchart. seriescollection [0]. datalabelscollection. add (); If (charttype. tostring (). indexof ("charttypepie ")! =-1) {DLS. position = chartdatalabelpositionenum. chlabelpositioncenter; DLS. haspercentage = false; // DLS. hasvalue = false; DLS. hascategoryname = false; // specifies whether the legend of the chart needs to be labeled as insertchart. haslegend = true; insertchart. legend. position = chartlegendpositionenum. chlegendpositionbottom;} // output file. int iimagelength = 0; int iimagewidth = 0; // get the settings from the config file // iimagelength = int. parse (webconfigurationmanager. appsettings ["showimagelength"]); // iimagewidth = int. parse (webconfigurationmanager. appsettings ["showimagewidth"]); iimagelength = 450; iimagewidth = 300; string strimagename = charttype. tostring () + "_" + guid. newguid (). tostring ("N") + ". PNG "; layspace. exportpicture (strabsolutepath + strimagename, "PNG", 450,300); // Add the image to placeholder, the string strimagetag = "

 

Use C # To draw a chart (pie chart line chart)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.