Chart is the root object for creating a chart. It stores all necessary data and some global properties required to produce a chart.
Managing Chart Areas
When a chart is created, one default chart area is automatically created also. It is returned by the ChartArea property. You can add your own chart areas to the ChartAreas collection returned by the ChartAreas property.
Managing Series Collection
All data series used in this chart should be added to SeriesCollection returned by the SeriesCollection property. Note that Z-order in which the series are drawn is determined by the order of adding them to the collection.
Binding XML
Instead of creating data points, adding them to data series and subsequent adding the series to the series collection, you can declare all necessary data in an XML file and bind it to the chart to achieve the same result. The XML must conform to the Aspose.Chart XML Schema that can be found in C:\Program Files\Aspose\Aspose.Chart\Schema\Aspose.Chart.xsd. Use the BindXML method to do that. The method accepts either the name of an XML file or an XML string.
Specifying Graphics
When a chart is created, it uses the default Graphics object that is created automatically. However, you can specify your own Graphics to make the chart to be drawn on it. Use the Graphics property for this purpose.
Creating and Obtaining the Chart Image
You can produce the chart image and then get it in several different formats.
Bitmap Object
To create and get a Bitmap object (for example, in order to insert it into a MS Word document using Aspose.Word), use the GetChartImage method.
Image
To create and save the image to a file, use the Save method passing to it the image file name with full path. The format of the image is specified using the extension of the file name. For example, if you specify "myfile.png", then the image will be saved in the PNG format. The following file extensions are recognized: .bmp, .gif, .jpg, .jpeg, .tiff. Alternatively, you can explicitly indicate the desired format by passing an ImageFormat object.
To create and save the image to the stream, use yet another overload of Save that accepts a stream object and an ImageFormat object.
Macromedia Flash
To create and save the image to the file in Macromedia Flash format, use the SaveToSwf method. This method will store the image as a 32bit bitmap in the Flash file resulting in a larger file, but no loss of image quality. You can specify an additional boolean parameter which indicates whether JPEG mode is on. In JPEG mode the image will be compressed using JPEG compression in the Flash file resulting in a small file, but with some loss of image quality.
You can use another overload of SaveToSwf to save the chart in Macromedia Flash format to the stream.
Setting a Size
You can control the size of the chart image using the Width and Height properties. The units are pixels. The default chart size is 500x400 pixels.
Setting a Background Color
Use the BackColor property to set the background color for the chart.
Setting a Layout of Chart Areas
If the chart contains multiple chart areas, you can specify how to lay them out in this chart. This is controlled by the ChartAreaLayout property. Additionally, you can explicitly specify the number of rows and columns of chart areas by setting the RowCount and ColumnCount properties, respectively.
Setting a Smoothing Mode
You can specify the smoothing mode that is used when the chart is drawn. Use the SmoothingMode property for this. The default value is AntiAlias. In addition to AntiAlias, you can specify HighQuality for high quality rendering or HighSpeed for high speed rendering.
Setting a Frame Border
The chart image might include a frame border. It is represented by the FrameBorder object returned by the FrameBorder property. This object provides several proprties that control the border appearance: border color, background color, the type of the border, and so on. Set the FrameBorder.BorderType property to anything different from BorderType.None to make the border visible.
Using Paint Events
Chart provides two events that occur when the chart is drawn. The Paint event occurs when the chart is drawn and the BackPaint event occurs when the chart background is drawn. The event handlers are represented by the PaintEventHandler delegated. These handlers receive an argument of type PaintEventArgs containing data related to this event.
Use the paint events to draw your own chart or chart background details if needed.
Code Sample
[C#]
Chart chart = new Chart();
// Adding a series
chart.SeriesCollection.Add(series);
// Setting background color
chart.BackColor = Color.Fuchsia;
// Setting size
chart.Width = 200;
chart.Height = 300;
// Setting chart areas layout
chart.ChartAreaLayout = LayoutType.Table;
// Setting frame border
chart.FrameBorder.BorderType = BorderType.Color;
chart.FrameBorder.BorderColor = Color.Gold;
chart.FrameBorder.BackColor = Color.Silver;
// Saving chart image
chart.Save("Chart.jpg");
[VB .NET]
Dim chart As Chart = New Chart()
' Adding a series
chart.SeriesCollection.Add(series)
' Setting background color
chart.BackColor = Color.Fuchsia
' Setting size
chart.Width = 200
chart.Height = 300
' Setting chart areas layout
chart.ChartAreaLayout = LayoutType.Table
' Setting frame border
chart.FrameBorder.BorderType = BorderType.Color
chart.FrameBorder.BorderColor = Color.Gold
chart.FrameBorder.BackColor = Color.Silver
' Saving chart image
chart.Save("Chart.jpg")