I'm trying to create a histogram in oxyplot. I followed the documentation on oxyplot.org (using ColumnSeries) and ended up with a histogram looking like this:
And my code looks like this:
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Items = new Collection<Item>
{
new Item {Label="200", Value=37},
new Item {Label = "400", Value=7},
new Item {Label="600",Value=23},
new Item {Label="800",Value=23},
new Item {Label="1000",Value=23}
};
var model = new PlotModel {Title = "Column Series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };
model.Axes.Add(new CategoryAxis { Position = AxisPosition.Bottom, ItemsSource = this.Items, LabelField = "Label" });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 });
model.Series.Add(new ColumnSeries { Title = "2009", ItemsSource = this.Items, ValueField = "Value" });
this.Model1 = model;
this.DataContext = this;
}
public Collection<Item> Items { get; set; }
public PlotModel Model1 { get; set; }
public class Item
{
public string Label { get; set; }
public double Value { get; set; }
}
}
}
I will add some other data eventually. My problem right now is that I want my "x-axis" to be linear and I also want my columns to fill upp the whole space between 0 to 200, and 200 to 400 etc. I've tried to change the axis to a LinearAxis but since I use OxyPlot's ColumnSeries I must have a CategoryAxis on the x-axis, otherwise it won't work. Can I change my CategoryAxis in some way so it looks like a LinearAxis or is it better to use another kind of series (already tried BarSeries and RectangleBarSeries, that didn't work either)? I also want to move the labels 200, 400, 600 etc. and place them under each "intervall line"