You can create a separate list that will work with RadzenColumnSeries
. The list will be of a class with two properties which are:
- Status: as
CategoryProperty
(status value as string eg. open, close ...)
- Projects: as
ValueProperty
(number of projects that fall in the current status)
Then create an item for each status and assign the number of projects that fall in that status.
projectStatus = new[]
{
new DataItem()
{
Status = "Open"
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.OPEN)
},
new DataItem()
{
Status = "Closed"
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.CLOSED)
},
//...
};
Working example:
@page "/chart"
<div class="container">
<div class="row">
<div class="col-sm-12 my-5">
<RadzenChart>
<RadzenColumnSeries Data="@projectStatus"
CategoryProperty="Status"
Title="Projects"
LineType="LineType.Dashed"
ValueProperty="Projects">
<RadzenSeriesDataLabels Visible="@showDataLabels" />
</RadzenColumnSeries>
<RadzenColumnOptions Radius="5" />
<RadzenValueAxis Min="0"
Max="@maxValue"/>
</RadzenChart>
</div>
</div>
</div>
@code {
bool showDataLabels = true;
List<Project> projects { get; set; }
DataItem[] projectStatus { get; set; }
int maxValue;
protected override void OnInitialized()
{
projects = new List<Project>();
projects.Add(new Project(ProjectStatus.OPEN));
projects.Add(new Project(ProjectStatus.CLOSED));
projects.Add(new Project(ProjectStatus.IN_PROGRESS));
projects.Add(new Project(ProjectStatus.DELETED));
projects.Add(new Project(ProjectStatus.NEW));
projects.Add(new Project(ProjectStatus.NEW));
projects.Add(new Project(ProjectStatus.OPEN));
projectStatus = new[]
{
new DataItem()
{
Status = ProjectStatus.OPEN.ToString(),
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.OPEN)
},
new DataItem()
{
Status = ProjectStatus.CLOSED.ToString(),
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.CLOSED)
},
new DataItem()
{
Status = ProjectStatus.IN_PROGRESS.ToString(),
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.IN_PROGRESS)
},
new DataItem()
{
Status = ProjectStatus.DELETED.ToString(),
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.DELETED)
},
new DataItem()
{
Status = ProjectStatus.NEW.ToString(),
Projects = projects.Count(x => x.ProjectStatus == ProjectStatus.NEW)
}
};
maxValue = projectStatus.Max(x => x.Projects);
base.OnInitialized();
}
class DataItem
{
public string Status { get; set; }
public int Projects { get; set; }
}
public class Project
{
public Project(ProjectStatus status)
{
this.ProjectStatus = status;
}
public ProjectStatus ProjectStatus { get; set; }
}
public enum ProjectStatus
{
OPEN,
CLOSED,
IN_PROGRESS,
DELETED,
NEW
}
}
Result:
