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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cannot render the chart

Thread ID:

Created:

Updated:

Platform:

Replies:

144364 May 2,2019 02:38 PM UTC May 9,2019 12:51 PM UTC Xamarin.Forms 3
loading
Tags: SfChart
Valerio Bordin
Asked On May 2, 2019 02:38 PM UTC

Hi,
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);
                    points.Add(point);
                }

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

                sfChart.Series.Add(serie);
            }

            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?

Bharathiraja K [Syncfusion]
Replied On 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. 
 
 
Regards, 
Bharathi. 


Valerio Bordin
Replied On May 9, 2019 12:25 PM UTC

Thank you.

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

Bharathiraja K [Syncfusion]
Replied On May 9, 2019 12:51 PM UTC

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon