简体   繁体   中英

Trouble with OxyPlot Heatmap Windows 8.1 Universal App VS 2015: Plot won't draw

When I run the program in the debugger all I get is the big gray "X" However this is only happens with Heatmaps. I AM able to draw line plots. I'm completely new to OxyPlot (I love it already) and I'm hoping there's something I'm leaving out that is required to draw HeatMaps.

The documentation for OxyPlot heatmaps is a little thin.

What am I missing?

Here's my 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>

And in MainPage,xaml.cs I say:

...
        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; }


    } ...

I got the same problem today. Everything is working except the Heatmaps. When using a Heatmap, the program is freezing. I tried the examples and debugged the OxyPlot source code to get an idea what causes this error. It turned out, that the problem occurs when converting a MemoryStream to an IRandomAccessStream. This is the source code which is doing this:

        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;
        }

The program freezes when var task = Task.Run(() => dw.WriteBytes(memoryStream.ToArray())); is called. But I don't know why this does not work... as a workaround I moved the dw.WriteBytes(memoryStream.ToArray()) and doing this without Threading which then works fine and the Heatmaps are displayed as intended. You then just have to wait for the ConvertToRandomAccessStream(MemoryStream memoryStream) call when setting the source of the BitmapImage.

Does anyone know why the WriteBytes method of the DataWriter causes the freeze when running inside a Task?

EDIT: I'am using OxyPlot Version 2015.1.893.0 for an Windows Store app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM