Line charts
A line chart consists of multiple data points that are connected by line segments. You can create a line chart using the Plot.Create.LineChart
method:
This method has a few overloads, differing mainly in the type of the first argument: the overload taking an IReadOnlyList<(double, double)>
(i.e., the one used in the example above) represents each individual data point as a tuple of coordinates (the first element is the X
coordinate and the second element is the Y
coordinate). The overload taking an IReadOnlyList<IReadOnlyList<double>>
represents each data point as an array of coordinates (again, the first element is the X
coordinate and the second element is the Y
coordinate). Finally, the overload taking an IReadOnlyList<double>
assumes that the values provided are only the Y
coordinates of the points, and that the points are equally spaced on the X
axis (this is useful e.g. if you have data that has been sampled at regular intervals from something and you do not care about the X
axis).
Optional parameters can be used to determine the appearance of some elements of the plot. Many of these are in common with other kinds of plots and are described in the page about scatter plots; here are the ones specific to line charts:
bool smooth
: by default, the points are connected by straight lines. If you set this totrue
, a smooth spline will be computed, which passes through all the data points.PlotElementPresentationAttributes linePresentationAttributes
: the presentation attributes for the line.PlotElementPresentationAttributes pointPresentationAttributes
: the presentation attributes for the data points.double pointSize
: the size of the data points (by default, this is0
, so that the data points are not drawn).IDataPointElement dataPointElement
: symbol used for each point (see the page describing theScatterPoints
plot element for more details).
Plotting multiple line charts
There are a few overloads of the LineCharts
method (note the plural s
), which can be used to draw multiple line charts on the same plot. Again, the different overloads can be use to plot data in different forms; there are also overloads taking exactly two collections of data points, which can be used if you need to plot just two lines. These overloads take very similar parameters to the LineChart
methods, but have the following parameters specified as arrays instead of individual objects:
IReadOnlyList<PlotElementPresentationAttributes> linePresentationAttributess
IReadOnlyList<PlotElementPresentationAttributes> pointPresentationAttributess
IReadOnlyList<double> pointSizes
IReadOnlyList<IDataPointElement> dataPointElements
This makes it possible to specify a different value for each data set. If these arrays are shorter than the number of data sets, the values are wrapped (e.g., if only two pointSizes
are specified and 3 data sets are being plotted, the third data set will use the same point size as the first data set).
The following example shows the effects of some of these settings:
As in a scatter plot, you can add additional elements to a line chart, e.g. a trendline.