Unable to render SfChart in Xamarin Forms ContentView

Hello, I cannot seem to get the SfChart to render in a ContentView (it seems to work fine in a ContentPage). 
I am using Xamarin Forms latest version (5) and version 19.1.0.55 of Syncfusion.Xamarin.SfChart.

I have tried this inside and outside StackLayout 

See below code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vm="clr-namespace:Dynamo.ViewModels.Fatigue;assembly=Dynamo"    
             xmlns:chart="clr-namespace:Syncfusion.SfChart.XForms;assembly=Syncfusion.SfChart.XForms"
             x:Class="Dynamo.Views.Fatigue.FatigueForecastView"
             x:DataType="vm:FatigueForecastViewModel">


    <StackLayout >
      
        <Label Text="Chart Title"/>

        <chart:SfChart x:Name="Chart" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Green">
            <chart:SfChart.PrimaryAxis>
                <chart:CategoryAxis />
            </chart:SfChart.PrimaryAxis>
            <chart:SfChart.SecondaryAxis>
                <chart:NumericalAxis />
            </chart:SfChart.SecondaryAxis>
        </chart:SfChart>
    </StackLayout>

</ContentView>

3 Replies 1 reply marked as answer

YP Yuvaraj Palanisamy Syncfusion Team April 9, 2021 01:06 PM UTC

Hi Paul Burkinshaw, 
 
Greetings from Syncfusion. 
 
We have analyzed your query and we suspect that the ContentView does not have the desired height & Width and it’s parent becomes StackLayout hence, please set the desired size of the ContentView as like in the below code example.

 
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"  
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:d="http://xamarin.com/schemas/2014/forms/design" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
             xmlns:chart="clr-namespace:Syncfusion.SfChart.XForms;assembly=Syncfusion.SfChart.XForm 
             mc:Ignorable="d"  
             VerticalOptions="FillAndExpand" 
             HorizontalOptions="FillAndExpand" 
             x:Class="ChartSample.ChartView"> 
  <ContentView.Content> 
      <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> 
            <Label Text="Chart Title" /> 
            <chart:SfChart x:Name="Chart"   
                           HorizontalOptions="FillAndExpand"  
                           VerticalOptions="FillAndExpand" 
                           BackgroundColor="Green"> 
                <chart:SfChart.PrimaryAxis> 
                    <chart:CategoryAxis /> 
                </chart:SfChart.PrimaryAxis> 
                <chart:SfChart.SecondaryAxis> 
                    <chart:NumericalAxis /> 
                </chart:SfChart.SecondaryAxis> 
            </chart:SfChart> 
        </StackLayout> 
  </ContentView.Content> 
</ContentView> 
                                                 
 
Also, we have prepared the sample for you reference. Please find the sample from the below link. 
 
  
Please let us know if you have any concern. 
 
Regards, 
Yuvaraj. 


Marked as answer

DY Dynamo April 13, 2021 11:00 AM UTC

This fixed the problem.

Many thanks
Paul


YP Yuvaraj Palanisamy Syncfusion Team April 14, 2021 05:55 AM UTC

Hi Paul, 
 
Thanks for your update. 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon