Can you programatically create charts?

1 Answer 119 Views
Chart
Philip Allwright
Top achievements
Rank 1
Philip Allwright asked on 25 Oct 2021, 09:16 AM

Is it possible to programatically create charts in Xamarin Forms?

In particular I want to create a bar chart that has between 1-30 data groups and in each group there can be up to 8 items.

e.g. The X axis could show classrooms (1-30), for each class room there are 1-8 timeslots, and the numeric Y axis would show student numbers.

Doing this in xaml is possible but messy. I had a quick look but couldnt see how to set up the series programtically.

 

Is this  possible and if so can you supply an example please.

Thanks

1 Answer, 1 is accepted

Sort by
0
Nikola
Telerik team
answered on 27 Oct 2021, 02:18 PM

Hi Philip,

Yes,  you can create a chart programmatically.  An example can be found here

Here is a sample chart definition using C#: 

var chart = new RadCartesianChart
{
    HorizontalAxis = new CategoricalAxis(),
    VerticalAxis = new NumericalAxis(),
    BindingContext = new ViewModel()
};

var series = new BarSeries();

series.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data"));

series.ValueBinding = new PropertyNameDataPointBinding { PropertyName = "Value" };
series.CategoryBinding = new PropertyNameDataPointBinding { PropertyName = "Category" };

chart.Series.Add(series);

For more chart examples check our SDK application: https://docs.telerik.com/devtools/xamarin/demos-and-sample-apps/sdk-browser-overview#sdk-browser-application.

Regards,
Nikola
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.
Tags
Chart
Asked by
Philip Allwright
Top achievements
Rank 1
Answers by
Nikola
Telerik team
Share this question
or