I've been trying to find a way to do this column chart with multiple columns but nothing looks like it will work so posting here. My problem is that it's not always the same each time the report will be run. So I'm building an attendance report which is based on the value and number of items selected from 2 listboxes on a previous form. So what is sent over to the report will vary, sometimes it may only be 1 person and 1 type of event, other times it could be 5 people at 3 different events. I need a way that it can see what events the user wants to get the attendance for and create a column for each event for each person that is selected. Any help would be greatly appreciated.
Thanks,
Andrew King
Thanks for the quick response. So that kinda works, it looks like your example has multiple lists, one for each GDP year. For me I can't do that, I'm sending one list into the chart. I have pasted the code, list contents and the graph it generates.
<SfChart Title="@ReportTitle" >
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" IsIndexed="true" ></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@reportDataList" Name="EventTypesData" XName="MemberIDNameData" YName="AttendedNumberData" Type="ChartSeriesType.Column" ></ChartSeries>
</ChartSeriesCollection>
<ChartLegendSettings Visible="true" ></ChartLegendSettings>
</SfChart>
List Item 1:
List Item 2:
List Item 3:
List Item 4:
Graph:
So the names aren't grouping to show one bar for each service. The name is just EventTypesData instead of the name of the events. Any advice is greatly appreciated.
Thanks for the sample. The only problem is everything you are doing is hard coded. I cannot hard code any of it. It has to loop through the list that is sent to it and then generate A chartSeries for each EventType. These EventTypes could be different each time the report is ran. I've tried to do a foreach loop in the CharSeriesCollection but I keep getting an error, I've gotten it for int and string also:
Severity Code Description Project File Line Suppression State
Error (active) CS1503 Argument 1: cannot convert from 'RCManagement.Pages.Program.AdminsManagersStaffOnly.AttendanceReport.ReportDataItems' to 'System.Collections.Generic.IEnumerable<object>' RCManagement c:\RCManagement\Pages\Program\AdminsManagersStaffOnly\AttendanceReportDisplay.razor 12
This is what I'm trying to do:
<ChartSeriesCollection>
@foreach(var reportData in reportDataList)
{
<ChartSeries DataSource=@reportData Name="EventTypesData" XName="MemberIDNameData" YName="AttendedNumberData" Type="ChartSeriesType.Column" ></ChartSeries>
}
</ChartSeriesCollection>
Thanks,
Andrew
|
@foreach (SalesInfo report in reportDataList)
{ Values.Add(report.EventTypesData); @if (report.EventTypesData != Values[Values.Count - 1]) { <ChartSeries DataSource=@reportDataList Name="@report.EventTypesData" XName="MemberIDNameData" YName="AttendedNumberData" Type="ChartSeriesType.Column"></ChartSeries> } } |
Thank you for the assistance. Just wanted to let you know that I was able to get it to work, you were close. First thing is that your sample didn't work at all the way it was coded. The only reason your graph is showing anything was because you left the hard coded Chart Series in the First collection. If you comment those 2 hard coded series then the graph is blank. This is because your check for the report.EventTypesData != Values[Values.Count -1] will always fail, the report.EventTypesData always equals the Values[Values.Count -1] because it was just added to that list. I tweaked your code and this is how it worked, I first had it check to see if the EventType it's trying to add is in the list, if it isn't, then it adds the ChartSeries and then adds that event type to the list. This makes it only add 1 Chart series for each event type in the list. I wouldn't have thought to do it this way without your sample so I really appreciate the time you put into this.
<SfChart Title="Events between 1/2/2022 - 1/9/2022">
<ChartEvents OnPointRender="PointRenderEvent"></ChartEvents>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartPrimaryYAxis Title="Sales in Dollar"></ChartPrimaryYAxis>
<ChartSeriesCollection>
@*<ChartSeries DataSource="@reportDataList" Name="Saturday Service" XName="MemberIDNameData" YName="AttendedNumberData" Type="ChartSeriesType.Column"></ChartSeries>
<ChartSeries DataSource="@reportDataList" Name="Sunday Service" XName="MemberIDNameData" YName="AttendedNumberData" Type="ChartSeriesType.Column"></ChartSeries>*@
</ChartSeriesCollection>
<ChartSeriesCollection>
@foreach (SalesInfo report in reportDataList)
{
@if (!Values.Contains(report.EventTypesData))
{
<ChartSeries DataSource=@reportDataList Name="@report.EventTypesData" XName="MemberIDNameData" YName="AttendedNumberData" Type="ChartSeriesType.Column"></ChartSeries>
}
Values.Add(report.EventTypesData);
}
</ChartSeriesCollection>
<ChartLegendSettings Visible="true"></ChartLegendSettings>
</SfChart>
Swetha,
It was no inconvenience at all, I only noted it for your information only. I tried a foreach loop multiple times before reaching out so you were able to get me in the right direction, so I really appreciate all the time you put into helping me. You can consider this ticket resolved.
Thanks,
Andrew