Hello,
I'm trying to make a trend chart where the amount of searches done on a webpage is set against the date the search happened. I want the user to be able to select the daterange they want to see the trend line for. I also want to make sure that the selected daterange is valid. All of this works, but stops working when I'm trying to set a min and max to the CategoryAxis. I can select any daterange except for a daterange that lies in the future? The Chart and DatePicker code is as follows:
<RadzenCard>
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">From</RadzenText>
<RadzenDatePicker @bind-Value="startDay" Change=@(args => OnManualDateChange(args, null, "MM/dd/yyyy")) Class="w-100" DateFormat="d" />
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">To</RadzenText>
<RadzenDatePicker @bind-Value="endDay" Change=@(args => OnManualDateChange(null, args, "MM/dd/yyyy")) Class="w-100" DateFormat="d" />
</RadzenCard>
<RadzenCard Class="w-100 mb-4" Style="display: flex; align-items: center; gap: 0.5rem">
<RadzenCheckBox @bind-Value="@trend" Name="trend"></RadzenCheckBox>
<RadzenLabel Text="Trend" For="trend" Style="margin-right: 1rem;" Class="rz-color-danger-dark" />
<RadzenCheckBox @bind-Value="@median" Name="median"></RadzenCheckBox>
<RadzenLabel Text="Median" For="median" Style="margin-right: 1rem;" Class="rz-color-success-dark" />
<RadzenCheckBox @bind-Value="@mean" Name="mean"></RadzenCheckBox>
<RadzenLabel Text="Mean" For="mean" Style="margin-right: 1rem;" Class="rz-color-info-dark" />
<RadzenCheckBox @bind-Value="@mode" Name="mode"></RadzenCheckBox>
<RadzenLabel Text="Mode" For="mode" Class="rz-color-warning-darker" />
</RadzenCard>
<RadzenChart>
@if (_recordsInRange.Count() > 1)
{
<RadzenLineSeries Smooth="true" Data="@_recordsInRange" CategoryProperty="DateTime" Title="Search Count per Date" ValueProperty="SearchCount" RenderingOrder="1">
<RadzenSeriesTrendLine Visible="@trend" Stroke="var(--rz-danger-dark)" LineType="LineType.Dashed" />
<RadzenSeriesMedianLine Visible="@median" Stroke="var(--rz-success-dark)" LineType="LineType.Dotted" />
<RadzenSeriesMeanLine Visible="@mean" Stroke="var(--rz-info-dark)" LineType="LineType.Dotted" />
<RadzenSeriesModeLine Visible="@mode" Stroke="var(--rz-warning-darker)" LineType="LineType.Dotted" />
</RadzenLineSeries>
}
else
{
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">There is not enough data available within the selected timeframe. Please select a timeframe that contains more data.</RadzenText>
}
<RadzenCategoryAxis Padding="20" Min="_startDay" Max="_endDay" >
<RadzenAxisTitle Text="Date" />
</RadzenCategoryAxis>
<RadzenValueAxis>
<RadzenGridLines Visible="true" />
<RadzenAxisTitle Text="Amount of Searches" />
</RadzenValueAxis>
</RadzenChart>
And the code to change the date:
void OnDateChanged(DateTime? from, DateTime? to, string format)
{
startDay = from ?? startDay;
endDay = to ?? endDay;
checkDateRangeValid(startDay, endDay);
filterRecords(startDay, endDay);
setMinMaxRangeForChart(startDay, endDay);
}
void checkDateRangeValid(DateTime from, DateTime to)
{
if (from >= to)
{
endDay = startDay.AddDays(1);
}
if (to <= from)
{
startDay = endDay.AddDays(-1);
}
}
void setMinMaxRangeForChart(DateTime from, DateTime to)
{
_startDay = from;
_endDay = to;
}
void filterRecords(DateTime from, DateTime to)
{
_recordsInRange = _records.Where(record => record.DateTime >= from && record.DateTime <= to);
}
The error we receive is as follows: