beto-rodriguez / LiveCharts2

Simple, flexible, interactive & powerful charts, maps and gauges for .Net, LiveCharts2 can now practically run everywhere Maui, Uno Platform, Blazor-wasm, WPF, WinForms, Xamarin, Avalonia, WinUI, UWP.
https://livecharts.dev
MIT License
4.39k stars 574 forks source link

Add MAUI (Android) Support? #1618

Open johnjore opened 1 month ago

johnjore commented 1 month ago

Is your feature request related to a problem? Please describe. Upgraded my Xamarin.Android project to MAUI (MAUI.Android?) and can't seem to use LiveCharts2 in a MAUI.Android project

Describe the solution you'd like Is it possible to add support for MAUI.Android?

Additional context Extract from project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-android</TargetFramework>

Small extract from XML (Resources/layout):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:card_view="http://schemas.android.com/apk/res-auto"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="5dp"
        card_view:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="8dp">

            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:scaleType="fitXY"
                android:id="@+id/GPXTypeLogo"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_gravity="left"
                android:contentDescription="@string/type"
                android:layout_marginLeft="@dimen/layout_marginLeft" />

            <CartesianChart
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/TrackRouteMap"
                android:id="@+id/TrackRouteElevation"
                android:scaleType="fitCenter"
                android:layout_marginLeft="@dimen/layout_marginLeft"
                android:layout_marginTop="-10dp"
                android:visibility="visible" />

Extract while setting up the RecyclerView:

        public ImageView? TrackRouteMap { get; set; }
        public CartesianChart? TrackRouteElevation { get; set; }

        public GPXViewHolder(Android.Views.View itemview, Action<int> listener) : base(itemview)
        {
            GPXTypeLogo = itemview?.FindViewById<ImageView>(Resource.Id.GPXTypeLogo);
            Name = itemview?.FindViewById<TextView>(Resource.Id.Name);
            Distance = itemview?.FindViewById<TextView>(Resource.Id.Distance);
            Ascent = itemview?.FindViewById<TextView>(Resource.Id.Ascent);
            Descent = itemview?.FindViewById<TextView>(Resource.Id.Descent);
            Img_more = itemview?.FindViewById<TextView>(Resource.Id.textViewOptions);
            TrackRouteMap = itemview?.FindViewById<ImageView>(Resource.Id.TrackRouteMap);
---> Fails with error below:
            TrackRouteElevation = itemview?.FindViewById<CartesianChart>(Resource.Id.TrackRouteElevation);
        }
Severity    Code    Description Project File    Line    Suppression State   Details
Error (active)  CS0311  The type 'LiveChartsCore.SkiaSharpView.Maui.CartesianChart' cannot be used as type parameter 'T' in the generic type or method 'View.FindViewById<T>(int)'. There is no implicit reference conversion from 'LiveChartsCore.SkiaSharpView.Maui.CartesianChart' to 'Android.Views.View'.  hajk    hajk\GPX\GPX.cs
beto-rodriguez commented 1 month ago

Hi

I am sorry, I never used Xamarin Android nor Xamarin iOS, can you help me with a minimal reproducible sample, then I can fix this much faster.

tjorvenK commented 1 month ago

Hi, I just stumbled upon your issue. I am using livecharts with maui and android. If you could provide some more information, maybe a small sample project, I could also be of help

johnjore commented 1 month ago

I ended up using oxyplot instead, at least for now. I'll try and find some time to create a mini project, but its essentially a .NET Android Application as defined in the VS templates:

image

In the olden days, this would probably have been called Xamarin.Android (as opposed to Xamarin.Forms, which is now MAUI)