Use the statistical analysis graph of the Asp.net page written in C #

Source: Internet
Author: User
Hope to be useful to everyone

String [] dataname = {"Jan", "FEB", "Mar", "APR", "may", "Jun "};
Int [] DATA = {100, 20, 50, 60,240, 20 };

/// <Summary>
/// Create a bar chart using office
/// </Summary>
/// <Param name = "dataname"> data name </param>
/// <Param name = "data"> data </param>
Public void graphicscolumnclustered (string [] dataname, int [] data)
{
//////////////////////////////////////// ///////////////////////////////
/// Use Office Web Components to draw a bar chart
// Declare the string that stores the data category and data value
String strdataname = "";
String strdata = "";

For (INT I = 0; I <data. length; I ++)
{
Strdataname + = dataname+ '/T ';
Strdata + = Data. Tostring () + '/T ';
}


// Create a chartspace object to place charts
Owc. chartspace objcspace = new owc. chartspaceclass ();
// Use the Add method of the chartspace object to create a chart
Owc. wcchart objchart = objcspace. charts. Add (0 );
// Specify the chart type
// Chcharttypecolumnclustered indicates the column chart
// Chcharttypearea, chcharttypebarclustered, chcharttypepie, chcharttyperadarline, chcharttymoothline, and circular chart)
Objchart. type = owc. chartcharttypeenum. chcharttypecolumnclustered;
// Set the illustration
// It mainly includes the legend (data type expressed by color), the graph question (icon title), and the data description of the X and Y axes (usually used to describe the data unit on each axis)
// Specifies whether a legend is required for a chart.
Objchart. haslegend = true;
// Specify the title
Objchart. hastitle = true;
Objchart. Title. Caption = "Monthly Income chart for the first half of the year ";

// Graph description of X and Y axes
Objchart. Axes [0]. hastitle = true;
Objchart. Axes [0]. Title. Caption = "";
Objchart. Axes [1]. hastitle = true;
Objchart. Axes [1]. Title. Caption = "month ";

// Add data
// Set the seriescollection attribute of chart objects. First, use the add method of seriescollection to create a group of data, and then use the setdata method to add data.
// Add a group of chart data
Objchart. seriescollection. Add (0 );
// Specify the name of the Data Group
Objchart. seriescollection [0]. setdata (owc. chartdimensionsenum. chdimseriesnames, (INT) owc. chartspecialperformancesenum. chdataliteral, "first half income ");
// Specify the data category
Objchart. seriescollection [0]. setdata (owc. chartdimensionsenum. chdimcategories, (INT) owc. chartspecialperformancesenum. chdataliteral, strdataname );
// Specify the data value
Objchart. seriescollection [0]. setdata (owc. chartdimensionsenum. chdimvalues, (INT) owc. chartspecialperformancesenum. chdataliteral, strdata );

// Display data
// Use the exportpicture method of the chart object to create the generated chart as an image, and then display
// Output the GIF file. The parameter is the file name, format, and image size.
If (system. Io. file. exists (system. Web. httpcontext. Current. server. mappath ("") + @ "/tmpfile.gif "))
{
System. Io. file. Delete (system. Web. httpcontext. Current. server. mappath ("") + @ "/tmpfile.gif ");
}
Objcspace. exportpicture (system. Web. httpcontext. Current. server. mappath ("") + @ "/tmpfile.gif", "GIF", 400,300 );
// Create a bitmap object from the generated image and output it to the response output stream
Bitmap mypalette = new Bitmap (system. Web. httpcontext. Current. server. mappath ("") + @ "/tmpfile.gif", true );
Mypalette. Save (system. Web. httpcontext. Current. response. outputstream, system. Drawing. imaging. imageformat. GIF );
Mypalette. Dispose ();

} 

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.