|
private void DrawChart()
{
// Place user code here to initialize the page
//Create a ChartSpace object to place the chart
OWC.ChartSpace objCSpace = new OWC.ChartSpaceClass ();
//Add a chart to the ChartSpace object, and the Add method returns the chart object
OWC.WCChart objChart = objCSpace.Charts.Add(0);
//Specify the type of chart. The type is obtained from the OWC.ChartChartTypeEnum enumeration value
objChart.Type = OWC.ChartChartTypeEnum.chChartTypeColumnClustered;
//Specify whether the chart needs a legend
objChart.HasLegend = true;
//Given title
objChart.HasTitle = true;
objChart.Title.Caption = "First half distribution map";
//The illustration of the given x,y axis
objChart.Axes[0].HasTitle = true;
objChart.Axes[0].Title.Caption = "Y: quantity";
objChart.Axes[1].HasTitle = true;
objChart.Axes[1].Title.Caption = "X: month";
//calculate data
/*categories and values can be represented by tab-separated strings*/
string strSeriesName = "Legend 1";
string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t'+"4" + '\t' + "5" + '\t' + "6" + '\t' ;
string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t'+"10" + '\t' + "12" + '\t' + "6" + '\t' ;
//Add a series
objChart.SeriesCollection.Add(0);
//The name of the given series
objChart.SeriesCollection[0].SetData (OWC.ChartDimensionsEnum.chDimSeriesNames,
+ (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);
//Given classification
objChart.SeriesCollection[0].SetData (OWC.ChartDimensionsEnum.chDimCategories,
+ (int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);
//Desired point
objChart.SeriesCollection[0].SetData
(OWC.ChartDimensionsEnum.chDimValues,
(int)OWC.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
//The relative path of the GIF file.
string strRelativePath = "./test.gif";
//Output to GIF file.
string strAbsolutePath = Server.MapPath(strRelativePath);
objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 350);
//Add the picture to the placeholder.
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
ChartHolder.Controls.Add(new LiteralControl(strImageTag));
} |
|