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 the X coordinate value, indicating the Month int [] Month = new int [3] {1, 2, 3}; // create the Y coordinate value, double [] Count = new double [3] {120,240,220}; // create a chart space ChartSpace mychartSpace = new ChartSpace (); // Add a chart object ChChart mychart = mychartSpace to the chart space. charts. add (0); // set the chart type. In this example, use the column mychart. type = ChartChartTypeEnum. chChartTypeColumnClustered; // you can specify attributes of a chart. // you can specify the legend mychart. hasLegend = true; // whether the topic mychart is required. hasTitle = true; // The theme content mychart. title. caption = "quarterly summary"; // set the x and y coordinates of mychart. axes [0]. hasTitle = true; mychart. axes [0]. title. caption = "month"; mychart. axes [1]. hasTitle = true; mychart. axes [1]. title. caption = "sales"; // Add three chart blocks mychart. seriesCollection. add (0); mychart. seriesCollection. add (0); mychart. seriesCollection. add (0); // set the chart block attributes // The title mychart. seriesCollection [0]. caption = "February"; // 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 mychart. seriesCollection [1]. caption = "February"; // 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 mychart. seriesCollection [2]. caption = "February"; // 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]); // generates the 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, which indicates the sales value. double [] Count = {120,240,220}; string strDataName = ""; string strData = ""; // create a chart space ChartSpace mychartSpace = new ChartSpace (); // Add a chart object ChChart mychart = mychartSpace in the chart space. 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 the bar mychart. type = ChartChartTypeEnum. chChartTypePie; // you can specify attributes of a chart. // you can specify the legend mychart. hasLegend = true; // whether the topic mychart is required. hasTitle = true; // The theme content mychart. title. caption = "quarterly summary"; // Add the chart block mychart. seriesCollection. add (0); // set the chart block attributes // category attribute 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 the image mychartSpace. exportPicture (Server. mapPath (". ") + @" \ test.gif "," gif ", 500,450); // load the image Image1.ImageUrl = Server. mapPath (". ") + @" \ test.gif ";}

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.