Firstly, Iet me start by saying I am completely new to C# and Blazor and this is my first project using the language and tools so I am learning as I go.
I am currently trying to use RadzenLineSeries to display Disk Usage (%).
If I choose to display a single disk, I have no issues.
However when trying to add multiple disks using a foreach loop, the properties then require me to convert the values to string. The Category value is Date and value property is a decimal.
This doesn't show any errors in visual studio however once I then run the application and load the page.... I get a runtime error in Dev Tools...
*Error: System.ArgumentException: Property 09/21/2024 16:45:07 does not exist*
* at Radzen.Blazor.CartesianSeries`1.IsDate(String propertyName)*
* at Radzen.Blazor.CartesianSeries`1.SetParametersAsync(ParameterView parameters)*
Each Disks values are recorded in SQL at the same time and all have the same datetime value for each interval.
Please can someone advise?
p.s apologies for the formatting... not sure what went wrong?
I suggest trying to reproduce the problem in our online demos (they are editable). Then we can see what the problem is. Right now we can't tell what is wrong just from looking at a screenshot.
Are you able to explain the exception to me please? I don't understand why it states the property does not exist?
blazor.server.js:1 [2024-09-22T11:18:08.558Z] Error: System.ArgumentException: Property 21/09/2024 16:45:07 does not exist
at Radzen.Blazor.CartesianSeries`1.IsDate(String propertyName)
at Radzen.Blazor.CartesianSeries`1.SetParametersAsync(ParameterView parameters)
public class DiskModel
{
public string Server { get; set; }
public string Disk_ID { get; set; }
public decimal Capacity { get; set; }
public decimal Free { get; set; }
public decimal Used { get; set; }
public decimal Free_PC { get; set; }
public decimal Used_PC { get; set; }
public DateTime Date { get; set; }
}
I see what you're doing now. Basically, you are querying a table to get the data for a single server. From this, you want a chart that has Date as the Category, Usage as the Value, and you want a series for each of the disks.
If this is correct, what I think you need to do is, instead of the foreach being on the whole data, you need to create a list of disk ids. Then use this list as the basis of your foreach loop and create a new "Data" variable that is the filter of your server data using the disk id.
i.e.
var diskIds = Disk_Stats.Select(d => d.Disk_ID).Distinct();
@foreach (var disk in diskIds)
{
var diskData = Disk_Stats.Where(d=>d.Disk_ID==disk);
string dDate = @D.Date.ToString();
<RadzenLineSeries Smooth="false" Data="@diskData "
CategoryProperty="@Date" Title="@Disk_ID"
LineType="LineType.Dashed" ValueProperty="Used_PC">
<RadzenMarkers Visible="@showMarkers"
MarkerType="MarkerType.Auto" />
<RadzenSeriesDataLabels Visible="false" />
</RadzenLineSeries>
}
I've wrote this on the hoof with no testing, but it should at least give you an idea.