问题与OxyPlot热图Windows 8.1通用应用VS 2015: Plot won't绘制
本文关键字:won Plot 绘制 2015 VS 热图 OxyPlot Windows 应用 1通 问题 | 更新日期: 2023-09-27 17:50:29
当我在调试器中运行程序时,我得到的是一个大的灰色"X"然而,这只发生在热图上。我能画线条图。我对OxyPlot完全陌生(我已经喜欢它了),我希望有一些我遗漏的东西是绘制热图所必需的。
关于OxyPlot热图的文档有点薄。
我错过了什么?
这是我的MainPage.xaml:
<Page
...
xmlns:oxy="using:OxyPlot.Windows"
mc:Ignorable="d">
<Page.DataContext>
<local:MainViewModel/>
</Page.DataContext>
<Grid x:Name="LayoutRoot" Background="White">
<oxy:PlotView x:Name="MyHeatMap" Model="{Binding plotModel1}"/>
</Grid>
</Page>
在MainPage, example。cs中我说:
...
namespace App1
{
using OxyPlot;
using OxyPlot.Series;
public class
MainViewModel
{
public MainViewModel()
{
this.plotModel1 = new PlotModel { Title = "Example 1" };
this.plotModel1.Axes.Add(new OxyPlot.Axes.LinearColorAxis
{
Position = OxyPlot.Axes.AxisPosition.Right,
Palette = OxyPalettes.Jet(500),
HighColor = OxyColors.Gray,
LowColor = OxyColors.Black
});
var heatMapSeries1 = new OxyPlot.Series.HeatMapSeries
{
X0 = 0.0,
X1 = 1.5,
Y0 = 0.0,
Y1 = 4.0,
Data = new Double[,] { { 0.1, 0.2 }, { 0.4, 0.1 }, { 0.3, 0.2 } }
};
this.plotModel1.Series.Add(heatMapSeries1);
}
public PlotModel plotModel1 { get; private set; }
} ...
我今天遇到了同样的问题。除了热图,一切都在工作。当使用热图时,程序会冻结。我尝试了这些示例并调试了OxyPlot源代码,以了解导致此错误的原因。事实证明,问题发生在将MemoryStream转换为IRandomAccessStream时。下面是源代码:
private static async Task<IRandomAccessStream> ConvertToRandomAccessStream(MemoryStream memoryStream)
{
var randomAccessStream = new InMemoryRandomAccessStream();
var outputStream = randomAccessStream.GetOutputStreamAt(0);
var dw = new DataWriter(outputStream);
var task = Task.Run(() => dw.WriteBytes(memoryStream.ToArray()));
await task;
await dw.StoreAsync();
await outputStream.FlushAsync();
return randomAccessStream;
}
调用var task = Task.Run(() => dw.WriteBytes(memoryStream.ToArray()));
时程序冻结。但我不知道为什么这不起作用……作为一种解决方案,我移动了dw.WriteBytes(memoryStream.ToArray())
,并在没有线程的情况下这样做,然后工作良好,热图按预期显示。当设置BitmapImage的源时,你只需要等待ConvertToRandomAccessStream(MemoryStream memoryStream)
调用。
有谁知道为什么WriteBytes方法的DataWriter导致冻结在一个任务内运行时?
编辑:我正在使用OxyPlot版本2015.1.893.0的Windows商店应用程序