【发布时间】:2017-08-30 07:47:44
【问题描述】:
我正在使用 OxyPlot 视图在图表中显示一些数据。直到昨天它一直正常工作。因为,我将数据库部分(sqlite)添加到我的应用程序中,所以每当我打开包含 OxyPlot 的活动页面时,它只会在移动屏幕上显示此消息:
Oxyplot 异常:对象引用未设置为 目的。引发了 system.NullReferenceException 类型的异常 在 Oxyplot.ReflectionPath..ctor(System.String path)[0x00006]
当System.NullReferenceException 被抛出但程序没有停止时,我试图通过放置一个断点来找到它发生的位置。
在我的活动中向用户界面添加一个PlotView 控件:
design d = new design();
var plotView = new PlotView(this);
plotView.Model = d.CreatePlotModelTest;
this.AddContentView(plotView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
更新:
我注意到,如果我在创建绘图模型时使用线性系列而不是条形系列,错误将会消失。但是,如果我尝试一个条形系列(在下面的代码中,您可以看到它的注释),应用程序将再次向我显示错误。
public PlotModel CreatePlotModelTest()
{
var plotModel = new PlotModel { Title = "OxyPlot Demo" };
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Maximum = 10, Minimum = 0 });
var series1 = new LineSeries
{
MarkerType = MarkerType.Circle,
MarkerSize = 4,
MarkerStroke = OxyColors.White
};
series1.Points.Add(new DataPoint(0.0, 6.0));
series1.Points.Add(new DataPoint(1.4, 2.1));
series1.Points.Add(new DataPoint(2.0, 4.2));
series1.Points.Add(new DataPoint(3.3, 2.3));
series1.Points.Add(new DataPoint(4.7, 7.4));
series1.Points.Add(new DataPoint(6.0, 6.2));
series1.Points.Add(new DataPoint(8.9, 8.9));
plotModel.Series.Add(series1);
/*var barSeries = new BarSeries
{
ItemsSource = new List<BarItem>(new[]
{
new BarItem{ Value = (2) },
new BarItem{ Value = (3) },
new BarItem{ Value = (4) },
new BarItem{ Value = (5) },
new BarItem{ Value = (6) }
}),
LabelPlacement = LabelPlacement.Inside,
LabelFormatString = "{2:0.0}"
};
plotModel.Series.Add(barSeries);
plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
plotModel.Axes.Add(new CategoryAxis
{
Position = AxisPosition.Left,
Key = "CakeAxis",
ItemsSource = new[]
{
"Apple cake",
"Baumkuchen",
"Bundt Cake",
"Chocolate cake",
"Carrot cake"
}
});*/
return plotModel;
}
有人知道用条形系列创建我的模型有什么问题吗?
【问题讨论】:
-
您在哪一行出现错误?
-
这是我的问题,我放了一个断点,但实际上VS没有显示我在哪一行得到错误。
-
energyBarsList和PlotView是什么?显示PlotView类,如果它是你创建的。 -
异常位置如图:在构造函数中:
Oxyplot.ReflectionPath..ctor -
也许调试器没有停止,因为您将断点放在异常之后。也正如@ShushiHangover 所说,你有位置。我赌
new PlotView(..)和new PlotModel(..)这样的构造函数。