microcharts-dotnet / Microcharts

Create cross-platform (Xamarin, Windows, ...) simple charts.
MIT License
2.03k stars 360 forks source link

Chart shows values as a flat line #316

Closed Coca162 closed 2 years ago

Coca162 commented 2 years ago

Hi, I am new to making graphs in C# and I thought this library was the best out there!

Right now I am using Microcharts in the following way (assume entries is the example data in the wiki)

var chart = new LineChart { Entries = entries };
SKBitmap bitmap = new(1000, 500);
using SKCanvas canvas = new(bitmap);
chart.Draw(canvas, 1000, 500);
using Stream imageStream = SKImage.FromBitmap(bitmap).Encode().AsStream();

I will then use stream later on

HOWEVER

When I finally see the data I get something like this: flat line BUT if I breakpoint (Visual Studio) before the imageStream is declared I get: image

This has driven me a bit insane. I have tried changing the type of chart, width/height, entries and other various things and it has to lead to the same flat line. Is there any way to not make this happen???

Note: To replicate the issue in a simple console application I had to loop this multiple times to get a similar result.

for (int i = 0; i < 10; i++)
{
    //same code as before
    await imageStream.CopyToAsync(File.Create($"{i}.png"));
}

Weirdly image 0 looked like this img0

Seuleuzeuh commented 2 years ago

I think it's due to the animation. Try to disable it and you'll be able to export the image. On the Chart object set Is animated property to false.

Le jeu. 2 juin 2022 à 03:17, Coca @.***> a écrit :

I am using Microcharts in the following way (assume entries is the example data in the wiki https://github.com/microcharts-dotnet/Microcharts/wiki)

var chart = new LineChart { Entries = entries };SKBitmap bitmap = new(1000, 500);using SKCanvas canvas = new(bitmap);chart.Draw(canvas, 1000, 500);using Stream imageStream = SKImage.FromBitmap(bitmap).Encode().AsStream();

I will then use stream later on HOWEVER

When I finally see the data I get something like this: [image: flat line] https://user-images.githubusercontent.com/62479942/171526436-e7d905a3-a7a9-4217-b41b-657f89addd13.png BUT if I breakpoint (Visual Studio) before the imageStream is declared I get: [image: image] https://user-images.githubusercontent.com/62479942/171526592-b76d49bd-32f9-4d2e-92dd-0aa5ea4925ed.png

This has driven me a bit insane. I have tried changing the type of chart, width/height, entries and other various things and it has to lead to the same flat line. Is there any way to not make this happen???

— Reply to this email directly, view it on GitHub https://github.com/microcharts-dotnet/Microcharts/issues/316, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSMXJQM3THBY52Y7HAUUETVNADQXANCNFSM5XTKRYMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Coca162 commented 2 years ago

@Seuleuzeuh Yep, that fixed it. Many thanks!