Data points
Plot elements that can be used to highlight data points include the classes ScatterPoints
(which draws a symbol at each point location), TextLabel
(which draws a single text label at the specified point), DataLabels
(which draws a label at each point location), DataLine
(which draws a line connecting multiple points), and Area
(which shades an area between two lines).
All of these classes have a generic type parameter T
that defines the kind of data point that they use to determine the coordinates of the points or the labels. In most instances, you will want T
to be IReadOnlyList<double>
, but there may be instances when you want to use a different data kind (e.g., for categorical data).
The following example shows how to use these elements:
Expand source code
The ScatterPoints
class
This plot element draws a symbol at each data point. The constructor for this class takes an IEnumerable<T>
parameter representing the data points, as well as a coordinate system for converting them to plot coordinates. Most of the time, the type parameter T
will be IReadOnlyList<double>
, which will allow the use of a regular coordinate system (e.g., linear or logarithmic coordinates).
The symbol that is drawn is determined by the value of the DataPointElement
property, which should be an instance of a class implementing the IDataPointElement
class.
The IDataPointElement
interface
This interface is used to define symbols to draw at particular points on the plot. The assumption is that the Graphics
object on which the plot is being created will be transformed in such a way that the symbol can be drawn centred at (0, 0)
. This means that implementations of this interface can be agnostic towards the position of the symbol and its size (because these will be taken care, e.g., by the ScatterPoints
class).
There are currently three implementations of this interface:
-
The
PathDataPointElement
class, which represents a symbol defined by aGraphicsPath
object (by default, a circle). The graphics path is filled and/or stroked using the attributes from thePresentationAttributes
object that is supplied to theIDataPointElement.Plot
method. -
The
GraphicsDataPointElement
class, which represents a symbol defined by aGraphics
object that is copied on the plot. In this case, the presentation attributes provided to thePlot
method will have no effect. -
The
ActionDataPointElement
class, which represents a symbol that is drawn by a customAction
, supplied to the constructor for this class. ThisAction
is responsible for drawing the symbol, and could do anything, in principle.
The TextLabel
class
This plot element draws a single text label on the plot, at the specified position, which is provided in the constructor, together with the text to draw and the coordinate system. Properties of this class can be used to determine the orientation and the alignment of the label.
The DataLabels
class
This plot element is similar to the ScatterPoints
class, but instead of drawing a symbol at each data point, it draws a text label. The label to draw is determined by the Label
property, which should be set to a function accepting the label index and coordinates, and returning the text of the label (either as a string
, an IEnumerable<FormattedText>
, or another kind of object that will be converted into a string in order to be displayed).
The DataLine
class
This plot element draws a line passing through all the data points. The line is drawn from the first to the last point in the collection, thus the points should be reasonably ordered.
The Area
class
This plot element is very similar to the DataLine
class, but rather than just drawing a single line, it fills an area comprised between a line and another line (the “baseline”). The baseline is defined by the GetBaseline
property, which should be set to a function accepting a single data point parameter and returning the corresponding baseline point. For example, if the data are represente as IReadOnlyList<double>
and the baseline should be the X
axis, you could use something like p => new double[] { p[0], 0 }
.