Each single diagram consists of a series of data points. A data point is represented by the DataPoint class. A DataPoint has one X value and one or more Y values. The X and Y values specify where on the chart the data point is drawn. The way the data point is drawn depends on the type of the chart specified by the Series.ChartType property.
Some types of charts require several Y values to draw properly, for example each data point on an OpenHighLowClose chart needs to have 4 Y values: Open, High, Low and Close values.
Creating a Data Point
There are two distinct ways of creating a data point. You can explicitly create a DataPoint objects. The DataPoint constructor provides several overloads so you can simply create a new data point, set its X and Y coordinates, or set its name and coordinates. Another way is using the DataPoints.Add method with specifying the coordinates of the data point; see WorkingWithDataSeries for details.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=2
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=3
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=20
Setting Values (Coordinates)
You can deal with data point values (coordinates) at any time using the following methods:
- Use the XValue property to get or set the data point X coordinate.
- Use the YValues property to get or set the data point Y coordinates.
- Use the SetValues method to set both X and Y data point coordinates.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=2
Setting a Color
You can control color of the data point using the Color property. Also, you can use the gradient color by setting the GradientType property to a value different from GradientType.None (which is default) and then setting the GradientColor property to the desired color.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=2
Setting a Font
You can set font and font color of the data point using the Font and FontColor properties, respectively.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=34
Setting a Background Image
You can get or set a DataPoint background image using the BackImage property that can be either image file path or URL. Image alignment is controlled by the BackImageAlign property that accepts an ImageAlignType enumeration value. The default value is ImageAlignType.None.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=3
Setting a Border
DataPoint may have a border whose appearance is controlled by several properties. BorderWidth specifies the width of the border. Its default value is 1; setting this value to 0 makes the border invisible. BorderColor specifies the color of the border. DashStyle gets or sets the data point border line style; the default value is Solid.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=2
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=12
Setting a Name
The DataPoint name might be set via the Name property.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=20
Setting a Text Label
DataPoint provides several properties that allow setting a text label. These properties are:
- LabelText . Gets or sets the text of the label.
- LabelValue . Gets or sets the value type of the label. The value type is represented by a DataLabelValueType enumeration value. Default is DataLabelValueType.YValue.
- LabelFormat . Gets or sets the format of the label. The formatting of the label complies with Formatting Types in .NET Framework.
- LabelPosition . Gets or sets the position of the label. Represented by a LabelPositionType enumeration value.
- LabelAngle . Gets or sets the angle of the label.
- IsLabelVisible . Gets or sets a boolean value indicating whether the label is visible.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=36
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=92
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=31
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=93
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=80
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=22
Assigning a Tooltip
You can easily assign a tooltip to a data point by setting its ToolTip property. This property accepts a ToolTip object which represents a tooltip and encapsulates its text, font, color, and fill color. The Tooltip has effect only in charts saved in the Macromedia Flash format using the Chart.SaveToSwf method.
Setting a URL
A clickable data point provides a possibility of setting an URL that will be associated with the point. Note that only Bar, Pie and Doughnut charts support clickable data points and only in charts saved in the Macromedia Flash format using the Chart.SaveToSwf method.
Use the Url property to get or set the destination URL of a clickable data point. The URL can be in absolute or relative format. For example, "http://www.aspose.com/mypage.html" and "mypage.html" are valid URLs.
Use the UrlTarget property to get or set the name of the anchor (bookmark) in the destination URL of a clickable data point.
Setting Custom Attributes
Each type of chart may support some custom properties, or attributes, which are only applicable to this type. All these attributes are stored in the CustomAttributes object that is returned by the CustomAttributes property. You can use it to additionally set up a chart of the certain type. Please refer to WorkingWithCustomAttributes for more information.
Code Sample
[C#]
// Creating a data point
DataPoint dataPoint = new DataPoint();
// Setting values
dataPoint.XValue = 10;
dataPoint.YValues = new double[] {5, -4.78, 452};
// Setting color
dataPoint.Color = Color.Red;
// Setting font
dataPoint.Font = new Font("Times New Roman", 12);
dataPoint.FontColor = Color.GhostWhite;
// Setting background image
dataPoint.BackImage = "DataPoint.png";
dataPoint.BackImageAlign = ImageAlignType.BottomLeft;
// Setting border
dataPoint.BorderWidth = 2;
dataPoint.BorderColor = Color.Turquoise;
dataPoint.DashStyle = DashStyle.DashDotDot;
// Setting label
dataPoint.LabelText = "I'm the best data point label";
dataPoint.LabelPosition = LabelPositionType.TopRight;
dataPoint.LabelAngle = 10;
dataPoint.IsLabelVisible = true;
// Setting name
dataPoint.Name = "I'm a wonderful data point";
// Creating and assigning tooltip
ToolTip toolTip = new ToolTip("I'm the nicest tooltip");
toolTip.Color = Color.ForestGreen;
toolTip.FillColor = Color.Gainsboro;
dataPoint.ToolTip = toolTip;
// Setting URL
dataPoint.Url = "http://www.aspose.com";
[VB .NET]
' Creating a data point
Dim dataPoint As DataPoint = New DataPoint()
' Setting values
dataPoint.XValue = 10
dataPoint.YValues = New Double()
{
5, -4.78, 452
}
' Setting color
dataPoint.Color = Color.Red
' Setting font
dataPoint.Font = New Font("Times New Roman", 12)
dataPoint.FontColor = Color.GhostWhite
' Setting background image
dataPoint.BackImage = "DataPoint.png"
dataPoint.BackImageAlign = ImageAlignType.BottomLeft
' Setting border
dataPoint.BorderWidth = 2
dataPoint.BorderColor = Color.Turquoise
dataPoint.DashStyle = DashStyle.DashDotDot
' Setting label
dataPoint.LabelText = "I'm the best data point label"
dataPoint.LabelPosition = LabelPositionType.TopRight
dataPoint.LabelAngle = 10
dataPoint.IsLabelVisible = True
' Setting name
dataPoint.Name = "I'm a wonderful data point"
' Creating and assigning tooltip
Dim toolTip As ToolTip = New ToolTip("I'm the nicest tooltip")
toolTip.Color = Color.ForestGreen
toolTip.FillColor = Color.Gainsboro
dataPoint.ToolTip = toolTip
' Setting URL
dataPoint.Url = "http://www.aspose.com"
Clarifies working with series of data points.
10/28/2005 7:29:17 AM - -83.217.194.222
Clarifies working with custom attributes.
10/28/2005 12:18:46 PM - -83.217.194.222