Skip to content

Commit 6e11e9e

Browse files
committed
Merge pull request #13 from seijikun/bar
[BarSeries] Update documentation
2 parents 564c889 + 6545549 commit 6e11e9e

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

models/series/BarSeries.png

-9.57 KB
Loading

models/series/BarSeries.rst

+86-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ BarSeries
66

77
A ``BarSeries`` shows the data as horizontal bars.
88

9-
.. image:: BarSeries.png
10-
119
Axes
1210
----
1311

@@ -32,11 +30,93 @@ The default format string for ``BarSeries`` is ``"{0}\n{1}: {2}"``
3230
See `MSDN <http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx>`_ for more information about format strings.
3331

3432

35-
Example
33+
Example(simple)
3634
-------
3735

36+
Here a simple example making use of very basic functionality to visualize the popularity of 5 different types of cake.
37+
38+
.. image:: BarSeries.png
39+
40+
.. sourcecode:: csharp
41+
42+
var model = new PlotModel{ Title = "Cake Type Popularity" };
43+
44+
//generate a random percentage distribution between the 5
45+
//cake-types (see axis below)
46+
var rand = new Random();
47+
double[] cakePopularity = new double[5];
48+
for(int i = 0; i < 5; ++i) {
49+
cakePopularity[i] = rand.NextDouble();
50+
}
51+
var sum = cakePopularity.Sum();
52+
53+
var barSeries = new BarSeries
54+
{
55+
ItemsSource = new List<BarItem>(new[]
56+
{
57+
new BarItem{ Value = (cakePopularity[0] / sum * 100) },
58+
new BarItem{ Value = (cakePopularity[1] / sum * 100) },
59+
new BarItem{ Value = (cakePopularity[2] / sum * 100) },
60+
new BarItem{ Value = (cakePopularity[3] / sum * 100) },
61+
new BarItem{ Value = (cakePopularity[4] / sum * 100) }
62+
}),
63+
LabelPlacement = LabelPlacement.Inside,
64+
LabelFormatString = "{0:.00}%"
65+
};
66+
model.Series.Add(barSeries);
67+
68+
model.Axes.Add(new CategoryAxis
69+
{
70+
Position = AxisPosition.Left,
71+
Key = "CakeAxis",
72+
ItemsSource = new[]
73+
{
74+
"Apple cake",
75+
"Baumkuchen",
76+
"Bundt Cake",
77+
"Chocolate cake",
78+
"Carrot cake"
79+
}
80+
});
81+
82+
83+
Example(grouped)
84+
-------
85+
86+
Here a more advanced example making use of grouping to always compare the two series' values.
87+
88+
.. image:: BarSeries_grouped.png
89+
3890
.. sourcecode:: csharp
3991

40-
var model = new PlotModel { Title = "BarSeries" };
41-
var barSeries = new BarSeries();
42-
model.Series.Add(barSeries);
92+
var model = new PlotModel
93+
{
94+
Title = "BarSeries",
95+
LegendPlacement = LegendPlacement.Outside,
96+
LegendPosition = LegendPosition.BottomCenter,
97+
LegendOrientation = LegendOrientation.Horizontal,
98+
LegendBorderThickness = 0
99+
};
100+
101+
var s1 = new BarSeries { Title = "Series 1", StrokeColor = OxyColors.Black, StrokeThickness = 1 };
102+
s1.Items.Add(new BarItem { Value = 25 });
103+
s1.Items.Add(new BarItem { Value = 137 });
104+
s1.Items.Add(new BarItem { Value = 18 });
105+
s1.Items.Add(new BarItem { Value = 40 });
106+
107+
var s2 = new BarSeries { Title = "Series 2", StrokeColor = OxyColors.Black, StrokeThickness = 1 };
108+
s2.Items.Add(new BarItem { Value = 12 });
109+
s2.Items.Add(new BarItem { Value = 14 });
110+
s2.Items.Add(new BarItem { Value = 120 });
111+
s2.Items.Add(new BarItem { Value = 26 });
112+
113+
var categoryAxis = new CategoryAxis { Position = AxisPosition.Left };
114+
categoryAxis.Labels.Add("Category A");
115+
categoryAxis.Labels.Add("Category B");
116+
categoryAxis.Labels.Add("Category C");
117+
categoryAxis.Labels.Add("Category D");
118+
var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0 };
119+
model.Series.Add(s1);
120+
model.Series.Add(s2);
121+
model.Axes.Add(categoryAxis);
122+
model.Axes.Add(valueAxis);

models/series/BarSeries_grouped.png

6.19 KB
Loading

0 commit comments

Comments
 (0)