Area charts
Area charts are very similar to line charts, except that the area between the line and a “baseline” (e.g., the X axis) is shaded. You can create them using the Plot.Create.AreaChart method:
using VectSharp;
using VectSharp.Plots;
using VectSharp.SVG;
// Create some random data.
Random rnd = new Random();
double[][] data = (from el in Enumerable.Range(0, 100) select new double[] { el + rnd.NextDouble(), 2 * el + 100 * rnd.NextDouble() }).ToArray();
// Create the line chart using the random data and the default settings.
Plot plot = Plot.Create.AreaChart(data);
// Render the plot to a Page and save it as an SVG document.
Page pag = plot.Render();
pag.SaveAsSVG(@"area.svg");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 area charts:
bool vertical: if this istrue(the default), the area between the data points and theXaxis is shaded. If this is set tofalse, the area between the data points and theYaxis is shaded instead.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 dataPresentationAttributes: this determines the presentation attributes for the line and the filled area.
Note that, in order for the area chart to be displayed correctly, the values for the x axis should be monotonically increasing (if vertical is true; this should apply to the y axis otherwise), that is, the data values should be provided in order of increasing x.
Stacked area charts
The Plot.Create.StackedAreaChart method can be used to create a stacked area chart. This consists of multiple areas stacked one over the other.
using VectSharp;
using VectSharp.Plots;
using VectSharp.SVG;
// Create some random data.
Random rnd = new Random();
double[][] data = (from el in Enumerable.Range(1, 100)
let x = el + rnd.NextDouble()
let y1 = 2 * el + 100 * rnd.NextDouble()
let y2 = y1 * 2
select new double[] { x, y1, y2 }).ToArray();
// Create the stacked area chart using the random data.
Plot plot = Plot.Create.StackedAreaChart(data,
xAxisTitle: "Horizontal axis",
yAxisTitle: "Vertical axis",
title: "Area chart");
// Render the plot to a Page and save it as an SVG document.
Page pag = plot.Render();
pag.SaveAsSVG(@"area.svg");This method has the same parameters as the AreaChart method. Here are a few notes to create a sucessful stacked area chart:
- The data should be provided in the following format:
- If
verticalistrue(the default),data[i][0]shall be thexvalue for all samples. Then,data[i][1],data[i][2], etc., are theyaxis values for each of the stacked lines. - If
verticalisfalse,data[i][1]shall be theyvalue for all samples. Then,data[i][0],data[i][2], etc., are thexaxis values for each of the stacked lines.
- If
- All data elements must be of the same length (
n + 1, wherenis the number of stacked areas). - The values for the
xaxis (oryaxis, ifverticalis false) should be monotonically increasing. - The values for the stacked lines should be in increasing order. E.g., if
verticalistrue,data[i][2]must be greater thandata[i][1]etc.