We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Cannot render the chart

I have a problem using SFChart. This is the fist time I use it and I use Xamarin.Forms, so it could be a mistake due to my inexperience.

I coded this method to create the chart:
public SfChart GetChart(MyModels.SyncChart chart)
            SfChart sfChart = new SfChart();
            sfChart.HorizontalOptions = LayoutOptions.StartAndExpand;
            sfChart.VerticalOptions = LayoutOptions.StartAndExpand;

            sfChart.Title = new ChartTitle();
            sfChart.Title.Text = chart.Title;

            LineSeries serie = null;
            ChartDataPoint point = null;
            ObservableCollection<ChartDataPoint> points = null;

            foreach (MyModels.Serie chartYSeries in chart.YSeries)
                points = new ObservableCollection<ChartDataPoint>();
                serie = new LineSeries();
                serie.Label = chartYSeries.Name;
                serie.EnableAnimation = true;

                int count = 1; 

                foreach (double value in chartYSeries.Values)
                    point = new ChartDataPoint(count, value);

                serie.ItemsSource = points;
                //serie.BindingContext = points;
                serie.YBindingPath = "YValue";
                serie.XBindingPath = "XValue";


            return sfChart;

    public class SyncChart
        public SyncChart()
            this.YSeries = new List<Serie>();

        public string Title { get; set; } = "Chart";

        public List<Serie> YSeries = null;

    public class Serie
        public Serie()
            this.Values = new List<double>();

        public string Name { get; set; } = "Unknown";

        public List<double> Values { get; set; }

and then I add it to XAML page. When I start the app, the chart is renderized (I see the chart title) but without data.

I would like to create the chart using only the code-behind.

Is there anyone who can help me?

3 Replies

BK Bharathiraja K Syncfusion Team May 3, 2019 07:34 AM UTC

Hi Valerio 
Greetings from Syncfusion. Currently we don’t have the desired size for chart. So, if you use the chart in StackLayout and set layout options as StartAndExpand means, we can’t get the height to chart. So, you should provide HeightRequest to Chart. If not, please change the Layoutoptions as FillAndExpand. It will be working fine. 
To know more about chart, please refer our online help document. 

VB Valerio Bordin May 9, 2019 12:25 PM UTC

Thank you.

The problem was on "LayoutOptions". I set HeightRequest parameter and I have resolved it.

BK Bharathiraja K Syncfusion Team May 9, 2019 12:51 PM UTC

Hi Valerio, 
We are glad that the reported problem resolved at your end. 

Live Chat Icon For mobile
Up arrow icon