- This page contains recipes for the Bar Series category.
- Visit the Cookbook Home Page to view all cookbook recipes.
- Generated by ScottPlot 4.1.52 on 7/9/2022
BarSeries Quickstart
A BarSeries plot allows each Bar to be created and customized individually.
var plt = new ScottPlot.Plot(600, 400);
// Create a collection of Bar objects
Random rand = new(0);
List<ScottPlot.Plottable.Bar> bars = new();
for (int i = 0; i < 10; i++)
{
int value = rand.Next(25, 100);
ScottPlot.Plottable.Bar bar = new()
{
// Each bar can be extensively customized
Value = value,
Position = i,
FillColor = ScottPlot.Palette.Category10.GetColor(i),
Label = value.ToString(),
LineWidth = 2,
};
bars.Add(bar);
};
// Add the BarSeries to the plot
plt.AddBarSeries(bars);
plt.SetAxisLimitsY(0, 120);
plt.SaveFig("barseries_quickstart.png");

BarSeries Horizontal
Horizontal orientation can be achieved by customizing the IsVertical property of each Bar.
var plt = new ScottPlot.Plot(600, 400);
Random rand = new(0);
List<ScottPlot.Plottable.Bar> bars = new();
for (int i = 0; i < 10; i++)
{
int value = rand.Next(25, 100);
ScottPlot.Plottable.Bar bar = new()
{
Value = value,
Position = i,
FillColor = ScottPlot.Palette.Category10.GetColor(i),
Label = value.ToString(),
IsVertical = false, // ENABLE HORIZONTAL ORIENTATION
};
bars.Add(bar);
};
plt.AddBarSeries(bars);
plt.SaveFig("barseries_horizontal.png");

BarSeries with Error Bars
Combine a BarSeries plot with an ErrorBar plot to achieve this effect.
var plt = new ScottPlot.Plot(600, 400);
// Create and add Bar objects to the plot
Random rand = new(0);
List<ScottPlot.Plottable.Bar> bars = new();
for (int i = 0; i < 10; i++)
{
int value = rand.Next(25, 100);
ScottPlot.Plottable.Bar bar = new()
{
Value = value,
Position = i,
FillColor = ScottPlot.Palette.Category10.GetColor(i),
LineWidth = 2,
};
bars.Add(bar);
};
plt.AddBarSeries(bars);
// Add error bars on top of the BarSeries plot
double[] xs = bars.Select(x => x.Position).ToArray();
double[] xErrs = bars.Select(x => (double)0).ToArray();
double[] ys = bars.Select(x => x.Value).ToArray();
double[] yErrs = bars.Select(x => (double)rand.Next(2, 20)).ToArray();
var err = plt.AddErrorBars(xs, ys, xErrs, yErrs);
err.LineWidth = 2;
err.CapSize = 5;
err.LineColor = Color.Black;
plt.SetAxisLimitsY(0, 120);
plt.SaveFig("barseries_error.png");
