我試圖在一行和幾個類別中繪製許多IntervalBarItems。在Oxyplot中,Categoryaxis將forevalBarSeries一個IntervalBarItem繪製到該行中。所以非常規如果我有三個系列,每個系列有4個項目 - 我有4個類別(3個BarItems)(系列1,系列2,系列3)。但我想要3個類別 - 每個系列中有4個項目 - 我可以通過爲每個項目設置CategoryIndex-Property來獲得此結果。在這裏,我得到IndexOutOfRangeException - 通過設置循環索引屬性。IndexOutOfRangeException嘗試在循環中設置CategoryIndex
MCVE:
XAML文件:
<Window x:Class="BarSeries_Stacked.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BarSeries_Stacked"
xmlns:oxy="http://oxyplot.org/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<oxy:PlotView Name="plot" />
</Grid>
</Window>
CS-文件:
namespace BarSeries_Stacked
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SetUpPlot();
}
private void SetUpPlot()
{
DateTime start = new DateTime(2017, 1, 1, 15, 0, 0);
DateTime start1 = new DateTime(2017, 1, 1, 15, 15, 0);
DateTime start2 = new DateTime(2017, 1, 1, 15, 20, 0);
DateTime start3 = new DateTime(2017, 1, 1, 15, 45, 0);
DateTime end = new DateTime(2017, 1, 1, 15, 10, 0);
DateTime end1 = new DateTime(2017, 1, 1, 15, 17, 0);
DateTime end2 = new DateTime(2017, 1, 1, 15, 30, 0);
DateTime end3 = new DateTime(2017, 1, 1, 15, 59, 0);
var model = new PlotModel();
model.IsLegendVisible = false;
model.Axes.Add(new OxyPlot.Axes.DateTimeAxis() { Position = AxisPosition.Bottom });
model.Axes.Add(new OxyPlot.Axes.CategoryAxis() { Position = AxisPosition.Left });
plot.Model = model;
var series = new OxyPlot.Series.IntervalBarSeries { Title = "Series 1", StrokeThickness = 1 };
model.Series.Add(series);
series.Items.Add(new IntervalBarItem { CategoryIndex = 0, Start = start.ToOADate(), End = end.ToOADate() });
series.Items.Add(new IntervalBarItem { CategoryIndex = 0, Start = start1.ToOADate(), End = end1.ToOADate() });
for (int i = 0; i < 10; i++)
{
var series2 = new OxyPlot.Series.IntervalBarSeries { Title = "Series "+i.ToString(), StrokeThickness = 1 };
series2.Items.Add(new IntervalBarItem { CategoryIndex = i, Start = start2.AddHours(i).ToOADate(), End = end2.AddHours(i).ToOADate() });
series2.Items.Add(new IntervalBarItem { CategoryIndex = i, Start = start3.AddHours(i).ToOADate(), End = end3.AddHours(i).ToOADate() });
model.Series.Add(series2);
}
}
}
}
只是用於測試放一些其他的指標(如1)CategoryIndex
嘗試設置爲類別斧標籤:categoryAxis.Labels.Add( 「A類」);對於每個CategoryIndex – Rekshino
現在我得到一個NullReferenceexception OxyPlot.Series.XYAxisSeries.GetClippingRect() –
它有幫助categoryAxis.Labels.Add(「..」)? – Rekshino