ASP. NET Server-Side Charting With OWC11 -- pie chart

Source: Internet
Author: User
What we are doing today is ASP. NET pie report. previously, I wanted to use the MSChart control that comes with VS to draw data, but it was not very convenient to use MSChart (in the Project). However, there are examples of MSChart painting. I hope you can give me some advice. This is why I found a better plug-in for creating a pie chart: OWC. You can download the plug-in from http://www.codeproject.com/kb/aspnet/owc11article.aspx. (try again. If Office version 2003 is installed on the PC, you must install this plug-in ).

Okay, no worries. paste the key source code directly:

Public void CreatePinReport ()
{
// Delete the generated file before creation
String deleteFileName = "stat.gif"; // name of the file to be deleted
Try
{
String [] rootDirs = Directory. GetDirectories ("http://images.cnblogs.com/"); // subdirectory of the current Directory:
String [] rootFiles = Directory. GetFiles ("http://images.cnblogs.com/"); // files in the current Directory:

Foreach (string s2 in rootFiles)
{
If (s2.Contains (deleteFileName ))
{
Console. WriteLine (s2 );
File. Delete (s2); // Delete an object
}
}
}
Catch (Exception)
{

}






// Create an X coordinate value, indicating the month

String [] month = GetNop_DictionaryWineType ();
// Create the Y coordinate value to indicate the sales volume
List <double> list = new List <double> ();

For (int I = 0; I <GetNop_DictionaryValueWineType (). Length; I ++)
{
// Count = GetSumOrderByProductCategoryID (Convert. ToInt32 (GetNop_DictionaryValueWineType () [I]);
List. Add (GetSumOrderByProductCategoryID (Convert. ToInt32 (GetNop_DictionaryValueWineType () [I]);
}
Double [] count = list. ToArray ();
String strDataName = "";
String strData = "";
// Create a chart Space
ChartSpace mychartSpace = new ChartSpace ();
MychartSpace. Border. Color = "White ";
// Add a chart object to the chart Space
ChChart mychart = mychartSpace. Charts. Add (0 );
// Set the data of each pie

For (int I = 0; I <count. Length; I ++)
{
StrDataName + = month [I] + "\ t ";
StrData + = count [I] + "\ t ";
}

// Set the chart type. In this example, use a pie chart.
Mychart. Type = ChartChartTypeEnum. chChartTypePie;
// Set chart attributes
// Do you need a legend?
Mychart. HasLegend = true;
// Whether a topic is required
Mychart. HasTitle = true;
// Subject content
Mychart. Title. Caption = "pie chart test ";
Mychart. Title. Font. Size = 10;
Mychart. Title. Font. Bold = false;
Mychart. Legend. Position = ChartLegendPositionEnum. chLegendPositionBottom;
Mychart. Legend. Interior. Color = "f9f9f9 ";
Mychart. Legend. Font. Size = 9;
Mychart. Legend. Border. Color = "White ";

// Add a chart Block
Mychart. SeriesCollection. Add (0 );
// Set chart block attributes
// Category attributes
Mychart. SeriesCollection [0]. SetData (ChartDimensionsEnum. chDimCategories,
(Int) chartspecialperformancesenum. chDataLiteral, strDataName );
// Value Attribute
Mychart. SeriesCollection [0]. SetData (ChartDimensionsEnum. chDimValues,
(Int) chartspecialperformancesenum. chDataLiteral, strData );
For (int j = 0; j <mychart. SeriesCollection [0]. Points. Count; j ++)
{
Mychart. SeriesCollection [0]. Points [j]. Border. Color = "White ";
}
// Display percentage
ChDataLabels mytb = mychart. SeriesCollection [0]. DataLabelsCollection. Add ();
Mytb. HasPercentage = true;
// Mytb. Border. Color = "White ";
Mytb. HasValue = true;
// Generate an image
MychartSpace. ExportPicture (Server. MapPath ("../images/") + @ "stat.gif", "gif", 700,400 );
// Load the image
This. ig. ImageUrl = "http://images.cnblogs.com/stat.gif ";
}

The following shows the Code:

The code is very simple and has detailed comments. I hope you can give me more advice ..

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.