0

I have created a SfChart in my code behind. I am getting no error but the chart doesn't display on the page. I think it may be a problem with my Xaml but I'm not sure. I have tried following the example here. My problem is similar in that everything builds and deploys and stepping through with the debugger I can see the different properties getting the data etc. Any help on this would be great.

XAML:

  <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <Grid x:Name="ChartGrid">
            <syncfusion:SfChart>

            </syncfusion:SfChart>
        </Grid>
  </StackLayout>

CODE BEHIND:

 ChartGrid.BindingContext = theViewModel;
                chart.PrimaryAxis = new DateTimeAxis();
                chart.PrimaryAxis.Title.Text = "Date";
                chart.Legend = new ChartLegend();
                chart.Legend.DockPosition = LegendPlacement.Top;
                chart.Legend.Title.Text = "Test";
                chart.Legend.BindingContext = testnames;
                chart.PrimaryAxis = new CategoryAxis() { Interval = 2, LabelPlacement = LabelPlacement.BetweenTicks };
                chart.SecondaryAxis = new NumericalAxis() { Minimum = 0, Maximum = 100, Interval = 5 };
                chart.Title.Text = "Player test scores";
                chart.Series.Add(new ColumnSeries()
                {
                    ItemsSource = playertestdata,
                    XBindingPath = dates.ToString(),
                    YBindingPath = testscores.ToString()
                });
                ChartGrid.Children.Add(chart);
Inkers
  • 219
  • 7
  • 27
  • The issue for me was that I hadn't added new SfChartRenderer(); in each of the projects e.g. in MainActivity.cs in Droid project etc after I had included the SyncFusion Nuget. See https://help.syncfusion.com/xamarin/introduction/download-and-installation#configuring-syncfusion-nuget-packages-in-visual-studio for reference - *Note to self - read ALL of the instructions in future!* – Inkers Oct 26 '16 at 22:59

1 Answers1

0

The SfChart is not displayed since the layout options for the grid was missed. We have modified the provided code snippet and it can be referred below

<Grid x:Name="ChartGrid" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <syncfusion:SfChart > 
            </syncfusion:SfChart>
 </Grid>

We have prepared a sample for your reference and it can be downloaded here