Skip to content

Commit 2dcffb4

Browse files
authored
Add example with vertical bars in BarSeriesExamples.cs (#2116)
* Add example with vertical bars in BarSeriesExamples.cs In the past, there was ColumnSeries, which could have the categories be placed on the X axis. The BarSeries needs them on the Y axis. The new example show how to do this using axis keys.
1 parent 989df42 commit 2dcffb4

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## Unreleased
5+
6+
### Added
7+
8+
- Example to demonstrate how to create vertical BarSeries
9+
410
## [2.2.0] - 2024-09-03
511

612
### Added

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Matthew Leibowitz <mattleibow@live.com>
9696
Memphisch <memphis@machzwo.de>
9797
Mendel Monteiro-Beckerman
9898
Menno Deij - van Rijswijk <m.deij@marin.nl>
99+
Menno van der Woude <mennowo@gmail.com>
99100
methdotnet
100101
Michael Fox <16841316+foxmja@users.noreply.github.com>
101102
Michael Hieke <mghie@gmx.net>
@@ -154,4 +155,4 @@ R. Usamentiaga
154155
Dmytro Shaurin
155156
Rustam Sayfutdinov
156157
Konstantin Stukov <havendv@gmail.com>
157-
jorgectf
158+
jorgectf

Source/Examples/ExampleLibrary/Series/BarSeriesExamples.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ public static PlotModel WithLabelsXAxisReversed()
8282
return WithLabels().ReverseXAxis();
8383
}
8484

85+
[Example("With vertical bars")]
86+
public static PlotModel WithVerticalBars()
87+
{
88+
var model = new PlotModel
89+
{
90+
Title = "With labels",
91+
};
92+
93+
var rnd = new Random(1);
94+
var series = new List<BarSeries>
95+
{
96+
new BarSeries { Title = "Base", XAxisKey = "values", YAxisKey = "categories" },
97+
new BarSeries { Title = "Inside", XAxisKey = "values", YAxisKey = "categories" },
98+
new BarSeries { Title = "Middle", XAxisKey = "values", YAxisKey = "categories" },
99+
new BarSeries { Title = "Outside", XAxisKey = "values", YAxisKey = "categories" }
100+
};
101+
102+
for (int i = 0; i < 4; i++)
103+
{
104+
foreach (var s in series)
105+
{
106+
s.Items.Add(new BarItem() { Value = rnd.Next(-100, 100) });
107+
}
108+
}
109+
110+
var categoryAxis = new CategoryAxis { Position = AxisPosition.Bottom, Key = "categories" };
111+
categoryAxis.Labels.Add("Category A");
112+
categoryAxis.Labels.Add("Category B");
113+
categoryAxis.Labels.Add("Category C");
114+
categoryAxis.Labels.Add("Category D");
115+
var valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0.06, MaximumPadding = 0.06, ExtraGridlines = new[] { 0d }, Key = "values" };
116+
117+
foreach (var s in series)
118+
{
119+
model.Series.Add(s);
120+
}
121+
122+
model.Axes.Add(categoryAxis);
123+
model.Axes.Add(valueAxis);
124+
return model;
125+
}
126+
85127
[Example("Stacked")]
86128
[DocumentationExample("Series/BarSeries")]
87129
public static PlotModel StackedSeries()

0 commit comments

Comments
 (0)