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.
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 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 ";
}