1. First download the owc11 COM Component
Http://www.microsoft.com/downloads/details.aspx? FamilyID = 7287252c-402e-4f72-97a5-e0fd290d4b76 & displaylang = en
2. Register owc11
Add the owc11.dll reference under the C:/Program Files/Common Files/Microsoft Shared/Web Components/11 file to the Project
3. Add
Using OWC11;
4. Example of starting coding:
Copy codeThe Code is as follows:
Public class ChartFactory
{
Public ChartFactory ()
{
InitTypeMap ();
//
// TODO: add the constructor logic here
//
}
Protected System. Web. UI. WebControls. Image imgHondaLineup;
Private string [] chartCategoriesArr;
Private string [] chartValuesArr;
Private OWC11.ChartChartTypeEnum chartType = OWC11.ChartChartTypeEnum. chChartTypeColumn3D; // Default Value
Private static Hashtable chartMap = new Hashtable ();
Private static string chartTypeCh = "vertical bar chart ";
Private static string chartTitle = "";
Private void InitTypeMap ()
{
ChartMap. Clear ();
OWC11.ChartChartTypeEnum [] chartTypes = new OWC11.ChartChartTypeEnum [] {ChartChartTypeEnum. chChartTypeColumnClustered,
ChartChartTypeEnum. chChartTypeColumn3D,
ChartChartTypeEnum. chChartTypeBarClustered,
ChartChartTypeEnum. chChartTypeBar3D,
ChartChartTypeEnum. chChartTypeArea,
ChartChartTypeEnum. chChartTypeArea3D,
ChartChartTypeEnum. chChartTypeDoughnut,
ChartChartTypeEnum. chChartTypeLineStacked,
ChartChartTypeEnum. chChartTypeLine3D,
ChartChartTypeEnum. chChartTypeLineMarkers,
ChartChartTypeEnum. chChartTypePie,
ChartChartTypeEnum. chChartTypePie3D,
ChartChartTypeEnum. chChartTypeRadarSmoothLine,
ChartChartTypeEnum. chChartTypeSmoothLine };
String [] chartTypesCh = new string [] {"vertical bar chart", "3D vertical bar chart", "Horizontal Bar Chart", "3D horizontal bar chart ", "area Statistical Chart", "3D area Statistical Chart", "Hollow pie chart", "line Statistical Chart", "3D line Statistical Chart", "line Statistical Chart with points", "Pie Chart ", "3D pie chart", "mesh Statistical Chart", "arc Statistical Chart "};
For (int I = 0; I <chartTypes. Length; I ++)
{
ChartMap. Add (chartTypesCh [I], chartTypes [I]);
}
}
Public ChartSpaceClass BuildCharts ()
{
String chartCategoriesStr = String. Join ("/t", chartCategoriesArr );
String chartValuesStr = String. Join ("/t", chartValuesArr );
OWC11.ChartSpaceClass oChartSpace = new OWC11.ChartSpaceClass ();
//------------------------------------------------------------------------
// Give pie and doughnut charts a legend on the bottom. For the rest
// Them let the control figure it out on its own.
//------------------------------------------------------------------------
ChartType = (ChartChartTypeEnum) chartMap [chartTypeCh];
If (chartType = ChartChartTypeEnum. chChartTypePie |
ChartType = ChartChartTypeEnum. chChartTypePie3D |
ChartType = ChartChartTypeEnum. chChartTypeDoughnut)
{
OChartSpace. HasChartSpaceLegend = true;
OChartSpace. ChartSpaceLegend. Position = ChartLegendPositionEnum. chLegendPositionBottom;
}
OChartSpace. Border. Color = "blue ";
OChartSpace. Charts. Add (0 );
OChartSpace. Charts [0]. HasTitle = true;
OChartSpace. Charts [0]. Type = chartType;
OChartSpace. Charts [0]. ChartDepth = 125;
OChartSpace. Charts [0]. AspectRatio = 80;
OChartSpace. Charts [0]. Title. Caption = chartTitle;
OChartSpace. Charts [0]. Title. Font. Bold = true;
OChartSpace. Charts [0]. SeriesCollection. Add (0 );
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection. Add ();
//------------------------------------------------------------------------
// If you're charting a pie or a variation thereof percentages make a lot
// More sense than values...
//------------------------------------------------------------------------
If (chartType = ChartChartTypeEnum. chChartTypePie |
ChartType = ChartChartTypeEnum. chChartTypePie3D |
ChartType = ChartChartTypeEnum. chChartTypeDoughnut)
{
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. HasPercentage = true;
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. HasValue = false;
}
//------------------------------------------------------------------------
// Not so for other chart types where values have more meaning
// Percentages.
//------------------------------------------------------------------------
Else
{
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. HasPercentage = false;
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. HasValue = true;
}
//------------------------------------------------------------------------
// Plug your own visual bells and whistles here
//------------------------------------------------------------------------
OChartSpace. Charts [0]. SeriesCollection [0]. Caption = String. Empty;
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. Font. Name = "verdana ";
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. Font. Size = 10;
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. Font. Bold = true;
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. Font. Color = "red ";
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. Position = ChartDataLabelPositionEnum. chLabelPositionCenter;
If (chartType = ChartChartTypeEnum. chChartTypeBarClustered |
ChartType = ChartChartTypeEnum. chChartTypeBar3D |
ChartType = ChartChartTypeEnum. chChartTypeColumnClustered |
ChartType = ChartChartTypeEnum. chChartTypeColumn3D)
{
OChartSpace. Charts [0]. SeriesCollection [0]. DataLabelsCollection [0]. Position = ChartDataLabelPositionEnum. chLabelPositionOutsideEnd;
}
OChartSpace. Charts [0]. SeriesCollection [0]. SetData (OWC11.ChartDimensionsEnum. chDimCategories,
Convert. ToInt32 (owc11.chartspecialperformancesenum. chDataLiteral), chartCategoriesStr );
OChartSpace. Charts [0]. SeriesCollection [0]. SetData (OWC11.ChartDimensionsEnum. chDimValues,
Convert. ToInt32 (owc11.chartspecialperformancesenum. chDataLiteral), chartValuesStr );
Return oChartSpace;
}
# Region attribute settings
Public string [] chartCategoriesArrValue
{
Get
{
Return chartCategoriesArr;
}
Set
{
ChartCategoriesArr = value;
}
}
Public string [] chartValuesArrValue
{
Get
{
Return chartValuesArr;
}
Set
{
ChartValuesArr = value;
}
}
Public string chartTypeValue
{
Get
{
Return chartTypeCh;
}
Set
{
ChartTypeCh = value;
}
}
Public string chartTitleValue
{
Get
{
Return chartTitle;
}
Set
{
ChartTitle = value;
}
}
# Endregion
}
// You must first place an Image on the page to display the generated Statistical Chart.
Public void ShowChart ()
{
// Initialize assignment
ChartFactory. chartCategoriesArrValue = chartCategories;
ChartFactory. chartValuesArrValue = chartValues;
ChartFactory. chartTitleValue = chartTitle;
ChartFactory. chartTypeValue = chartType;
OWC11.ChartSpaceClass oChartSpace = chartFactory. BuildCharts ();
String path = Server. MapPath (".") + @ "/images/Chart.jpeg"; // generate an image and save the page as a png GIF Image
OChartSpace. ExportPicture (path, "jpeg", 745,500 );
Image1.ImageUrl = path; // display the Statistical Chart
}
// To save the Statistical Chart, refer to the previous article.
// Because each statistical chart generated will overwrite the original image, you can use the date and time as the image name if necessary, but this will produce many images that need to be processed in a timely manner, you do not need to overwrite the original image with the same name.