Adding dynamically created chart to a Fragment

Hi,

I followed the "Getting Started Xamarin.Android Chart(SfChart)" Documentation and was wondering, how I can add that dynamically created Chart to a specific Fragment. In the demo project, the chart is loaded directly.

My Fragment xml looks like this:




1 Reply

DD Devakumar Dhanapoosanam Syncfusion Team April 25, 2022 10:02 AM UTC

Hi Lukas Bredemeier,


We have achieved your requirement adding chart using xml as per in the below code example.


activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:id="@+id/RootLayout">

    <com.syncfusion.charts.SfChart

        android:id="@+id/chart"

        android:layout_height=" fill_parent"

        android:layout_width="fill_parent" />

</LinearLayout>


protected override void OnCreate(Bundle savedInstanceState)

{

    base.OnCreate(savedInstanceState);

    ….

   

    // Set our view from the "main" layout resource

    SetContentView(Resource.Layout.activity_main);

 

    SfChart chart = FindViewById(Resource.Id.chart) as SfChart;

 

    ….

}


Please find the sample in the attachment and let us know if you need any further assistance on this.


Regards,

Devakumar D


Attachment: 174596_18cec02c.zip

Loader.
Up arrow icon