Hi all,
we have a XAML chart which works fine if data is set in the viewmodel when the page is drawn. If we update the observable collection (itemsource) later, only the x-axis labels are drawn but neither the bars nor the Y-axis is drawn (Xamarin Forms latest version with latests version of Telerik charts)
Here is our XAML:
<telerikChart:RadCartesianChart Grid.Row="6" Margin="35,0,10,5" BackgroundColor="Red">
<telerikChart:RadCartesianChart.Palette>
<telerikChart:ChartPalette>
<telerikChart:ChartPalette.Entries>
<telerikChart:PaletteEntry FillColor="White" StrokeColor="White"/>
<telerikChart:PaletteEntry FillColor="Pink" StrokeColor="Pink" />
</telerikChart:ChartPalette.Entries>
</telerikChart:ChartPalette>
</telerikChart:RadCartesianChart.Palette>
<telerikChart:RadCartesianChart.Grid>
<telerikChart:CartesianChartGrid StripLinesVisibility="None" YStripeColor="Red" YStripeAlternativeColor="Red" XStripeColor="Red" XStripeAlternativeColor="Red"/>
</telerikChart:RadCartesianChart.Grid>
<telerikChart:RadCartesianChart.HorizontalAxis>
<telerikChart:CategoricalAxis LineColor="White" LabelTextColor="White" GapLength="0.7"/>
</telerikChart:RadCartesianChart.HorizontalAxis>
<telerikChart:RadCartesianChart.VerticalAxis>
<telerikChart:NumericalAxis LineColor="Red" LabelTextColor="White"/>
</telerikChart:RadCartesianChart.VerticalAxis>
<telerikChart:RadCartesianChart.Series>
<telerikChart:BarSeries CombineMode="Cluster" ItemsSource="{Binding Revenue, Mode=TwoWay}">
<telerikChart:BarSeries.ValueBinding>
<telerikChart:PropertyNameDataPointBinding PropertyName="Value"/>
</telerikChart:BarSeries.ValueBinding>
<telerikChart:BarSeries.CategoryBinding>
<telerikChart:PropertyNameDataPointBinding PropertyName="Category"/>
</telerikChart:BarSeries.CategoryBinding>
</telerikChart:BarSeries>
<telerikChart:BarSeries CombineMode="Cluster" ItemsSource="{Binding Expenditure, Mode=TwoWay}">
<telerikChart:BarSeries.ValueBinding>
<telerikChart:PropertyNameDataPointBinding PropertyName="Value"/>
</telerikChart:BarSeries.ValueBinding>
<telerikChart:BarSeries.CategoryBinding>
<telerikChart:PropertyNameDataPointBinding PropertyName="Category"/>
</telerikChart:BarSeries.CategoryBinding>
</telerikChart:BarSeries>
</telerikChart:RadCartesianChart.Series>
</telerikChart:RadCartesianChart>
And here is the code which then updates the viewmodel - as said, the labels (Category) on the X-Axis work, but not the values or the Y-Axis:
try {
List<SumStat> sumStatList = bindableDataPackage.sumStats;
var revenues = new ObservableCollection<CategoricalData>();
var expenditures = new ObservableCollection<CategoricalData>();
foreach (var stat in sumStatList) {
if (stat.sumplus < 50000) {
revenues.Add(new CategoricalData { Category = stat.day, Value = stat.sumplus });
expenditures.Add(new CategoricalData { Category = stat.day, Value = stat.summinus });
}
}
// these 2 properties of type observable collection trigger the update
Revenue = revenues;
Expenditure = expenditures;
} catch (Exception e) {
StarFinanz.Core.Diagnostics.Trace.TraceInformation("Error: " + e.Message);
}