I am trying to display date or month in X axis as below, it works fine. I can see the columnseries and weight number on y axis but not months on X axis. I tried alternatively using Date instead of month but I cant see dates either
If i bind directly my AllBodyStats list object by defining binding on XBindingPath an YBindingPath, I can see the dates on X axis. Am I missing something? why it doesnt work using ChartDataPoint
xaml;
<chart:SfChart x:Name="Chart" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<chart:SfChart.Title>
<chart:ChartTitle Text="{Binding ChartTitle}"/>
</chart:SfChart.Title>
<chart:SfChart.PrimaryAxis>
<chart:DateTimeAxis IntervalType="Months" Interval="1">
<chart:DateTimeAxis.Title>
<chart:ChartAxisTitle Text="{resx:Translate Date}"></chart:ChartAxisTitle>
</chart:DateTimeAxis.Title>
</chart:DateTimeAxis>
</chart:SfChart.PrimaryAxis>
<chart:SfChart.SecondaryAxis>
<chart:NumericalAxis Minimum="0" Maximum="{Binding NumericalAxisMax}" Interval="{Binding NumericalAxisInterval}" >
<chart:NumericalAxis.Title>
<chart:ChartAxisTitle Text="{Binding NumericalAxisTitle}" ></chart:ChartAxisTitle>
</chart:NumericalAxis.Title>
</chart:NumericalAxis>
</chart:SfChart.SecondaryAxis>
<chart:SfChart.Series>
<chart:ColumnSeries ItemsSource="{Binding NumericMonthStats, Mode=OneWay}" EnableAnimation = "true" AnimationDuration="0.8" >
<chart:ColumnSeries.DataMarker>
<chart:ChartDataMarker/>
</chart:ColumnSeries.DataMarker>
</chart:ColumnSeries>
</chart:SfChart.Series>
</chart:SfChart>
viewmodel:
public ObservableCollection<ChartDataPoint> NumericMonthStats{ get; set; }
foreach (var BodyStat in AllBodyStats.OrderBy(o=>o.DateCreated))
{
string month = BodyStat.DateCreated.ToString("MMMM", Helpers.Settings.CurrentCultureInfo);
NumericMonthStats.Add(new ChartDataPoint(month, (double)BodyStat.Weight)); // using month
NumericMonthStats.Add(new ChartDataPoint(BodyStat.DateCreated.Date, (double)BodyStat.Weight)); // using date
}
using my custom list object
<chart:SfChart.Series>
<chart:ColumnSeries ItemsSource="{Binding AllBodyStats}" XBindingPath="DateCreated" YBindingPath="Weight">
<chart:ColumnSeries.DataMarker>
<chart:ChartDataMarker/>
</chart:ColumnSeries.DataMarker>
</chart:ColumnSeries>
</chart:SfChart.Series>