BarSeries

BarSeries is used to create clustered or stacked bar charts.

The BarSeries requires a CategoryAxis.
The Values collection must contain the same number of elements as the number of categories in the CategoryAxis.
You can define a ItemsSource and ValueField, or add the values manually to the Values collection.

BarSeries.png

Note
  • Set MinimumPadding = 0 on the value axis to make sure the bars start at the edge of the plot area
  • Set AbsoluteMinimum = 0 if the user should not be able to zoom/pan beyond the bottom of the bar

Model
You can create a bar chart with the following code:
var tmp = new PlotModel();
tmp.Axes.Add(new CategoryAxis { ItemsSource = items, LabelField = "Label" });
tmp.Axes.Add(new LinearAxis(AxisPosition.Left) { MinimumPadding = 0, AbsoluteMinimum = 0 });
tmp.Series.Add(new BarSeries { Title = "2009", ItemsSource = items, ValueField = "Value1" });

XAML
Bar charts can also be defined in XAML:
<oxy:Plot Title="Bar series" LegendPlacement="Outside" LegendPosition="RightTop" LegendOrientation="Vertical">
  <oxy:Plot.Axes>
    <oxy:CategoryAxis ItemsSource="{Binding Items}" LabelField="Label"/>
    <oxy:LinearAxis MinimumPadding="0" AbsoluteMinimum="0"/>
  </oxy:Plot.Axes>
  <oxy:Plot.Series>
    <oxy:BarSeries Title="2009" ItemsSource="{Binding Items}" ValueField="Value1"/>
    <oxy:BarSeries Title="2010" ItemsSource="{Binding Items}" ValueField="Value2"/>
    <oxy:BarSeries Title="2011" ItemsSource="{Binding Items}" ValueField="Value3"/>
  </oxy:Plot.Series>
</oxy:Plot>

Properties
BarWidth Width of the bars (fraction of the available width)
FillColor The fill color of the bars
IsStacked Flag determining if the bars are stacked. All series should have this flag set.
StrokeColor Color of the border around the bars.
StrokeThickness Thickness of ther border around the bars.
ItemsSource Source for the items collection
ValueField Property name of the field used to fill the Values collection.
Values Collection of bar values. The number of values must be the same as the number of categories on the category axis.


Example
See Examples/WPF/BarSeries and the ExampleBrowser.

Last edited Aug 15, 2011 at 1:27 PM by objo, version 2

Comments

Jivraj Feb 26, 2014 at 6:50 AM 
Similarly How to draw the bar series in windows 8 apps xaml