我正在尝试在oxyplot中创建直方图。我按照oxyplot.org(使用ColumnSeries)上的文档进行操作,最后得到一个如下所示的直方图:
我的代码看起来像这样:
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; }
}
}
}
我最终会添加一些其他数据。我现在的问题是我希望我的“x轴”是线性的,我也希望我的列填充0到200和200到400之间的整个空间等等。我试图将轴更改为a LinearAxis但是因为我使用OxyPlot的ColumnSeries,我必须在x轴上有一个CategoryAxis,否则它将无法工作。我可以以某种方式更改我的CategoryAxis,因此它看起来像一个LinearAxis或者更好地使用另一种类型的系列(已经尝试过的BarSeries和RectangleBarSeries,它们也不起作用)?我还想移动标签200,400,600等,并将它们放在每个“intervall line”
之下