microcharts-dotnet / Microcharts

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

[Bug] BarChart is not rendering well in integration with QuestPDF in asp.net #323

Open ibrahimkais opened 1 year ago

ibrahimkais commented 1 year ago

Describe the bug

I'm using microcharts with QuestPdf to generate PDF reports. I have a report that has a bar chart which doesn't reflect the entries with the value had been given and as you see in the attached screenshots it randomly renders the chart and it doesn't accurately reflects the bar value.

Which platform and version is this for? aspnet webapi .net 6 Azure Kubernetes container

To Reproduce the following is the BarChart object created

BarChart chart = new() { Entries = _model .GroupBy(item => item.ExpiryDate?.ToString("yyyy-MM") ?? default) .OrderBy(group => group.Key) .Select(group => new ChartEntry((group.Count() / _model.Count) * 100f) { Label = group.Key, ValueLabel = group.Count().ToString(), ValueLabelColor = SKColor.Parse("#000000"), TextColor = SKColor.Parse("#000000"), Color = SKColor.Parse($"#{rnd.Next(0x1000000):X6}") }), LabelColor = SKColor.Parse("#000000"), LabelTextSize = 10, LabelOrientation = Orientation.Vertical, ValueLabelOrientation = Orientation.Horizontal, BarAreaAlpha = 60, MaxValue = 100, IsAnimated = false, Typeface = SKTypeface.FromFamilyName("Arial"), Margin = 10, };

Steps to reproduce the behavior:

  1. create an aspnet webapi .net 6 application
  2. install the following references
    • HarfBuzzSharp.NativeAssets.Linux Version="2.8.2.3"
    • Microcharts Version="0.9.5.9"
    • QuestPDF Version="2022.11.0"
    • SkiaSharp Version="2.88.3"
    • SkiaSharp.NativeAssets.Linux.NoDependencies Version="2.88.3"
  3. try to create the invoice sample from QuestPDF
  4. as in QuestPDF documentation, try to use the above BarChart object with the invoice sample
  5. Run the application and view the report

Expected behavior Of course the expected behavior is finding the BarChart reflects the appropriate bar heights based on the given values.

Screenshots First Example image image

image image

Device OS: Edition Windows 11 Pro Version 22H2 OS build 22621.900 Experience Windows Feature Experience Pack 1000.22638.1000.0

I'm using Adobe Acrobat to view the generated PDF files

@shelbaz

TheObliterator commented 11 months ago

Did you find any resolution to this? I think I have a similar problem using the radial gauge in QuestPDF in a linux docker container. For me the very first render is incorrect, but subsequent renders seem ok. I suspect the bars are being animated despite animation being disabled. I'll update if I find anything further.

TheObliterator commented 11 months ago

I found a fix relating to animation in microcharts which I suspect will resolve my issue. Could it be relevant to your scenario? https://github.com/microcharts-dotnet/Microcharts/pull/300

Note: That fix is only in the v1.x branch so for now I'm adding a short delay in my render to workaround the animation issue.