Generate charts using OWC in ASP. NET 2.0

Source: Internet
Author: User

To display the chart type in ASP. NET 2.0, you can use the OWC component of MS office 2003 to conveniently view the chart. In the project, add a reference to microsoft office web components 11.0, and then use using Microsoft. Office. Interop. Owc11;

1. Generate a bar chart

// Create an X coordinate value, indicating the month
Int [] Month = new int [3] {1, 2, 3 };
// Create the Y coordinate value to indicate the sales volume
Double [] Count = new double [3] {120,240,220 };
// Create a chart Space
ChartSpace mychartSpace = new ChartSpace ();
// Add a chart object to the chart Space
ChChart mychart = mychartSpace. Charts. Add (0 );
// Set the chart type. In this example, use a column.
Mychart. Type = ChartChartTypeEnum. chChartTypeColumnClustered;
// Set chart attributes
// Do you need a legend?
Mychart. HasLegend = true;
// Whether a topic is required
Mychart. HasTitle = true;
// Subject content
Mychart. Title. Caption = "quarterly summary ";
// Set the x and y coordinates
Mychart. Axes [0]. HasTitle = true;
Mychart. Axes [0]. Title. Caption = "month ";
Mychart. Axes [1]. HasTitle = true;
Mychart. Axes [1]. Title. Caption = "sales volume ";
// Add three chart Blocks
Mychart. SeriesCollection. Add (0 );
Mychart. SeriesCollection. Add (0 );
Mychart. SeriesCollection. Add (0 );
// Set chart block attributes
// Title
Mychart. SeriesCollection [0]. Caption = "August ";
// Value Attribute of X coordinate
Mychart. SeriesCollection [0]. SetData (ChartDimensionsEnum. chDimCategories,
(Int) chartspecialperformancesenum. chDataLiteral, Month [0]);
// Value Attribute of y coordinate
Mychart. SeriesCollection [0]. SetData (ChartDimensionsEnum. chDimValues,
(Int) chartspecialperformancesenum. chDataLiteral, Count [0]);
// The second block
Mychart. SeriesCollection [1]. Caption = "August ";
// Value Attribute of X coordinate
Mychart. SeriesCollection [1]. SetData (ChartDimensionsEnum. chDimCategories,
(Int) chartspecialperformancesenum. chDataLiteral, Month [1]);
// Value Attribute of y coordinate
Mychart. SeriesCollection [1]. SetData (ChartDimensionsEnum. chDimValues,
(Int) chartspecialperformancesenum. chDataLiteral, Count [1]);
// The third block
Mychart. SeriesCollection [2]. Caption = "August ";
// Value Attribute of X coordinate
Mychart. SeriesCollection [2]. SetData (ChartDimensionsEnum. chDimCategories,
(Int) chartspecialperformancesenum. chDataLiteral, Month [2]);
// Value Attribute of y coordinate
Mychart. SeriesCollection [2]. SetData (ChartDimensionsEnum. chDimValues,
(Int) chartspecialperformancesenum. chDataLiteral, Count [2]);
// Generate an image
MychartSpace. ExportPicture (Server. MapPath (".") + @ "\ test.jpg", "jpg", 500,450 );
// Load the image
Image1.ImageUrl = Server. MapPath (".") + @ "\ test.jpg ";
}

2. Generate a pie chart

Protected void Page_Load (object sender, EventArgs e)
{
// Create an X coordinate value, indicating the month
Int [] Month = {1, 2, 3 };
// Create the Y coordinate value to indicate the sales volume
Double [] Count ={ 120,240,220 };
String strDataName = "";
String strData = "";
// Create a chart Space
ChartSpace mychartSpace = new ChartSpace ();
// 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]. ToString () + "\ t ";
}
// Set the chart type. In this example, use a column.
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 = "quarterly summary ";
// 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 );
// Display percentage
ChDataLabels mytb = mychart. SeriesCollection [0]. DataLabelsCollection. Add ();
Mytb. HasPercentage = true;
// Generate an image
MychartSpace. ExportPicture (Server. MapPath (".") + @ "\ test.gif", "gif", 500,450 );
// Load the image
Image1.ImageUrl = Server. MapPath (".") + @ "\ test.gif ";
}

Related Articles]

  • Use OWC to draw statistical charts in ASP.net
  • Use the ReportViewer control in ASP. NET 2.0
  • ASP. NET 2.0 makes statistical charts easy

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.