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?