Bar charts
A bar chart can be used to plot numerical values for a categorical variable. You can create a bar chart using the Plot.Create.BarChart
method:
This method has two overloads:
- The generic overload
BarChart<T>
takes an argument of typeIReadOnlyList<(T, double)>
(as in the example) and calls theToString
method on theT
item to display the category labels. - The overload that takes an argument of type
IReadOnlyList<double>
assumes that the supplied data represent the height of the bars, and does not show any category labels.
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 bar charts:
bool vertical
: if this istrue
(the default), the base of the bars lies on theX
axis and the bars go from bottom to top. If this isfalse
, the base of the bars lies on theY
axis and the bars go from left to right.double margin
: this determines the amount of space between consecutive bars.PlotElementPresentationAttributes dataPresentationAttributes
: this determines the appearance (stroke, fill, etc) of the bars.
Stacked bar charts
The two overloads of the Plot.Create.StackedBarChart
method can be used to plot a stacked bar chart, i.e., a plot where multiple bars of different colours are stacked one on top of the other. The overload that takes a first parameter of type IReadOnlyList<(T, IReadOnlyList<double>)>
uses the first element of each tuple (of type T
) to determine the category labels, as in the BarChart<T>
method, while the second element (which is an array of double
s) represents the heights for each stacked bar in the category. The other overload takes a first parameter of type IReadOnlyList<IReadOnlyList<double>>
and is similar to the overload creating a simple bar chart from an IReadOnlyList<double>
: the first parameter is an array of arrays, and each array refers to all the stacked bars in a single category (again, category labels are not shown here).
Most of the parameters for these methods are the same as for the BarChart
method, with the exception of IReadOnlyList<PlotElementPresentationAttributes> dataPresentationAttributes
, which is an array instead of being a single element. The elements of this array are used to determine the apperance of each bar in the stack; if the array contains fewer elements than bars, they are wrapped.
Clustered bar charts
A clustered bar chart is similar to a collection of multiple “mini bar charts” one next to the other. These can be created using the Plot.Create.ClusteredBarChart
method, which as usual has two overloads: the overload that takes a first parameter of type IReadOnlyList<(T, IReadOnlyList<double>)>
uses the first element of each tuple (of type T
) to determine the category labels, while the second element (which is an array of double
s) represents the heights for each clustered bar in the category. The other overload takes a first parameter of type IReadOnlyList<IReadOnlyList<double>>
and is similar to the overload creating a simple bar chart from an IReadOnlyList<double>
: the first parameter is an array of arrays, and each array refers to all the clustered bars in a single category (again, category labels are not shown here).
The parameters for this method are similar to the StackedBarChart
methods, but here, instead of a single double margin
parameter, there are two double interClusterMargin
and double intraClusterMargin
, which determine the margin between clusters and within clusters, respectively.