LiveCharts2 icon indicating copy to clipboard operation
LiveCharts2 copied to clipboard

MAUI basic sample only display when navigated using Shell for both Android and iOS. Normal navigation does not render

Open hbraasch opened this issue 2 years ago • 13 comments

Describe the bug Initially: MAUI basic sample crashes for both Android and iOS with[LiveChartsCore.SkiaSharpView.Maui.MotionCanvas is incompatible]. Sample app is a simple CartesianChart based on MAUI install example Finally: Realized it has to do with [Shell] or normal navigation (see later discussion).

To Reproduce Steps to reproduce the behavior:

  1. Go to github repository for sample project: https://github.com/hbraasch/LiveChartsMauiSample.git
  2. Clone project and run for both Android and iOS
  3. Observe exception

Expected behavior Line chart should display

Screenshots image

Smartphone (please complete the following information):

  • Device: Latest emulators for IOS and Android
  • MAUI RC3

hbraasch avatar May 19 '22 03:05 hbraasch

Hi!

Thanks for the report, did you try .UseSkiaSharp(true) ?

https://lvcharts.com/docs/Maui/2.0.0-beta.220/Overview.Installation

This will be moved before the Create a View Model section to clarify

beto-rodriguez avatar May 19 '22 03:05 beto-rodriguez

Yes, its in there. Unfortunately. Must be a different problem. Have found a lot of regression problems with MAUI RC. Could be the issue resolves itself 😊 Regards.

hbraasch avatar May 19 '22 06:05 hbraasch

Hi

My sincere apologies! I forgot to add [.UseSkiaSharp(true)] in the repro project. It now works with the chart defined in XAML.

However (as it started for me), I prefer defining my GUIs using code-behind, and the code I created to embed a graph does not render. Here is the code example, it is also in the updated repro on Github

internal class CodeBehindMainPage : ContentPage
    {
        public CodeBehindMainPage()
        {
            var chart = new CartesianChart();
            chart.Series = new ISeries[]
            {
                new LineSeries<double>
                {
                    Values = new double[] { 2, 1, 3, 5, 3, 4, 6 },
                    Fill = null
                }
            };
            var grid = new Grid();
            grid.Add(chart);
            Content = grid;
        }
    }

Any idea what I'm doing wrong?

Thanks and regards

hbraasch avatar May 19 '22 21:05 hbraasch

I forgot to add [.UseSkiaSharp(true)]

Glad to hear that, so the control is working!

I think that you second question is not related with the library, try to add another control first, like a button or something from MAUI, then see if it renders, if it does but the chart does not then the issue is from this library.

Something that helps me is to set a background color to the grid, then you can see if the grid has a valid size, some times depending on the container it does not renders as we think it would,

beto-rodriguez avatar May 19 '22 21:05 beto-rodriguez

I've now noticed that if I navigate to the code-behind page using [Shell], it renders. But if I navigate to it using my regular approach (which works if I replace the graph with a label), it renders fine. Regular approach:

MainPage = new NavigationPage(new CodeBehindMainPage());

Any ideas maybe?

hbraasch avatar May 19 '22 21:05 hbraasch

Not completely sure.

Being honest, I think that that kind of issues have a low chance to be an issue in this library, it could be an issue with SkiaSharp or MAUI.

but feel free to re-open this issue if you think that this issue is related with this library.

beto-rodriguez avatar May 19 '22 21:05 beto-rodriguez

Thanks for looking at this. I'll generate a repro project and raise it as a issue under MAUI and see how they react. Regards

hbraasch avatar May 19 '22 22:05 hbraasch

Issue raised at MAUI: https://github.com/dotnet/maui/issues/7350

hbraasch avatar May 19 '22 23:05 hbraasch

I've now discovered the chart does not display while running under the debugger. If running outside the debugger, all works fine.

Any possibility there is a [if (Debugger.IsAttached)... somewhere inside your code?

hbraasch avatar May 20 '22 06:05 hbraasch

Thanks for the Research, it seems that the error is here in LiveCharts, I tested your repo and added a view containing a SKCanvasView (from skia sharp) and it works 🤔

Any possibility there is a [if (Debugger.IsAttached)... somewhere inside your code?

Not as far as I remember... need to find what is wrong here

beto-rodriguez avatar May 20 '22 14:05 beto-rodriguez

Hope you find it. Its a great library!

hbraasch avatar May 21 '22 01:05 hbraasch

This seems a Maui issue, I added information to the issue you opened in Maui, lets wait for them to fix that, if they do not, then we could build a workaround.

beto-rodriguez avatar Jun 05 '22 18:06 beto-rodriguez

Great, Thanks

hbraasch avatar Jun 05 '22 21:06 hbraasch

Since beta.860 we removed the support for the XAML preview in MAUI, so this should be already working. Thanks for the report.

beto-rodriguez avatar Jul 30 '23 22:07 beto-rodriguez