I'm hoping someone can help me with some unexpected behaviour. Using the demo RadzenChart / LineChart as a template, I've made a chart that shows two years' worth of data. The trouble is that is all shows as one row, instead of stacking the years.
Each RadzenLineSeries refers to an array of DataItem objects, just like the demo - in my case, the DataItem is comprised of a string called Date, and a decimal called Consumption. Each array contains a complete year of DataItem objects, one for each month. If I don't have data for that month, the DataItem gets a zero value.
My expectation is that these years would be stacked on top of each other, but I'm not sure what I could be doing wrong. Any ideas would be greatly appreciated (or possibly there's something blindingly obvious that I'm missing?)
<RadzenChart>
<RadzenLineSeries Smooth="true" Data="@priorYearData" CategoryProperty="Date" Title="@priorYear.ToString()" LineType="LineType.Solid" ValueProperty="Consumption">
<RadzenMarkers Visible="true" MarkerType="MarkerType.Triangle"></RadzenMarkers>
<RadzenSeriesDataLabels Visible="true"></RadzenSeriesDataLabels>
</RadzenLineSeries>
<RadzenLineSeries Smooth="true" Data="@currentYearData" CategoryProperty="Date" Title="@currentYear.ToString()" LineType="LineType.Solid" ValueProperty="Consumption">
<RadzenMarkers Visible="true" MarkerType="MarkerType.Triangle"></RadzenMarkers>
<RadzenSeriesDataLabels Visible="true"></RadzenSeriesDataLabels>
</RadzenLineSeries>
<RadzenCategoryAxis Padding="20" Formatter="@FormatAsMonth" />
<RadzenValueAxis Formatter="@FormatTwoDecimals">
<RadzenGridLines Visible="true" />
<RadzenAxisTitle Text="Consumption in m3" />
</RadzenValueAxis>
</RadzenChart>
Helper functions:
public DataItem[] GetMonthlyReadings(IEnumerable<MonthlyConsumptionEstimate> estimates, int year)
{
DataItem[] tmpItems = new DataItem[12];
for (int i = 0; i < 12; i++)
{
tmpItems[i] = new DataItem
{
Consumption = estimates.FirstOrDefault(o => o.Month == i+1)?.Consumption ?? 0.0m,
Date = new DateTime(year, i+1, 1).ToString()
};
}
return tmpItems;
}
string FormatAsMonth(object value)
{
if (value != null)
{
return Convert.ToDateTime(value).ToString("MMM");
}
return string.Empty;
}
string FormatTwoDecimals(object value)
{
return ((double)value).ToString("F2");
}