OWC (Microsoft Office Web Components) is a data binding ActiveX Control used by Microsoft Office. It is available when you install the office. You can also install it separately (download from google ), using OWC to create a pie chart and a column chart makes it easy to develop and efficient. The main principle of OWC is to generate an image based on the input data, then, the developer loads the image to the corresponding position to achieve the effect. I personally feel that the generated image is rough, but it is encapsulated well. Just enter the data as required by the function and it will be OK, you can set the background color, Font, and size of an image.
During Development in vs2005/2008, right-click "--" add reference "--" Com-"Microsoft Office Web components 11 (this is when office2007 is installed, and 2003 is directly called Microsoft OWc)
Pie chart:
Copy to ClipboardReference: [www.bkjia.com] protected void pieBtn_Click (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 ();
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]. ToString () + "\ t ";
StrData + = count [I]. ToString () + "\ 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 (".") + @ "\ stat.gif", "gif", 700,400 );
// Load the image
This. ig. ImageUrl = "stat.gif" + "? Temp = "+ new Random (). Next (1,100) + "";;
}
Bar chart:
Copy to ClipboardReference: [www.bkjia.com] protected void columnarBtn_Click (object sender, EventArgs e)
{
Int [] month = {1, 2, 3 };
// Create the Y coordinate value to indicate the sales volume
Double [] count ={ 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 );
MychartSpace. Border. Color = "White ";
// 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 = "bar 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 ";
// Set the x and y coordinates
Mychart. Axes [1]. HasTitle = true;
Mychart. Axes [1]. Title. Caption = "coordinate ";
Mychart. Axes [1]. Title. Font. Size = 9;
For (int I = 0; I <count. Length; I ++)
{
Mychart. SeriesCollection. Add (I );
Mychart. SeriesCollection [I]. Caption = count [I]. ToString ();
Mychart. SeriesCollection [I]. SetData (ChartDimensionsEnum. chDimCategories, (int) chartspecialperformancesenum. chDataLiteral, month [I]);
Mychart. SeriesCollection [I]. SetData (ChartDimensionsEnum. chDimValues, (int) chartspecialperformancesenum. chDataLiteral, count [I]);
}
MychartSpace. ExportPicture (Server. MapPath (".") + @ "\ stat1.gif", "gif", 700,400 );
// Load the image
This. ig. ImageUrl = "stat1.gif" + "? Temp = "+ new Random (). Next (1,100) + "";;
}
In this way, you can input the corresponding data according to your actual situation, or set the color font according to your preferences.