LiveCharts2
LiveCharts2 copied to clipboard
MAUI basic sample only display when navigated using Shell for both Android and iOS. Normal navigation does not render
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:
- Go to github repository for sample project: https://github.com/hbraasch/LiveChartsMauiSample.git
- Clone project and run for both Android and iOS
- Observe exception
Expected behavior Line chart should display
Screenshots
Smartphone (please complete the following information):
- Device: Latest emulators for IOS and Android
- MAUI RC3
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
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.
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
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,
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?
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.
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
Issue raised at MAUI: https://github.com/dotnet/maui/issues/7350
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?
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
Hope you find it. Its a great library!
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.
Great, Thanks
Since beta.860 we removed the support for the XAML preview in MAUI, so this should be already working. Thanks for the report.