| @Html.EJS().Grid("container1").RowTemplate("#rowtemplate").Render() <script id="rowtemplate" type="text/x-template"> <tr style="height: 30px;">
<td style="padding-left:130px">
<div style="width: 16px; height: 16px; margin-left: 1px; border-radius: 16px; background:${color}"></div>
</td>
<td style="text-align:center;"> ${text} </td>
<td style="text-align:center;"> ${yValue} </td>
<td style="text-align:center;"> ${xValue} </td>
</tr> </script> |
Dear Syncfusion Team,
I have a similar problem in Blazor, but the Charts elements do not have a "ShowZero" property.
I have a stacked bar chart and "0" values are covering/hiding other values.
I checked in <ChartSeries>, <ChartMarker> and <ChartDataLabel> Elements but couldn't find a corresponding setting.
What would be the correct solution here?
Thanks
Klaus.
|
<SfChart>
<ChartEvents OnDataLabelRender="LabelRender"></ChartEvents>
</SfChart>
@code {
void LabelRender(TextRenderEventArgs args)
{
if (args.Text == "0%")
{
args.Text = String.Empty;
}
}
} |
Hi Swetha,
Thanks alot, this is working perfrectly.
I also tried with <Template> inside the <ChartDataLabel> but that didn't work for some reason (showing no labels at all).
Thanks
Klaus.
Hi Klaus,
Thanks for being patience. We have fixed the reported issue and generated custom nuget with fixed changes. We request you to ensure your application by installing this custom nuget. This fix will be available in our upcoming weekly patch release which is scheduled to be rolled out on 12th April 2022. We appreciate your patience until then.
Custom NuGet : https://www.syncfusion.com/downloads/support/directtrac/general/ze/Syncfusion.Blazor.Charts.20.1.0.481373772923.zip
Kindly revert us if you have any concerns.
Regards,
Durga Gopalakrishnan.
Hi Klaus,
We are glad to announce that our v20.1.0.48 patch release is rolled out; we have added the fix for reported issue. You can use the latest Syncfusion.Blazor.Charts NuGet package.
NuGet Package : https://www.nuget.org/packages/Syncfusion.Blazor.Charts/
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Durga Gopalakrishnan.
Hi Steven,
You can hide categories with a zero value before sending them to the view. The usual way is to filter the list so the pie chart only receives items that actually have data. That way the chart won’t draw empty slices or labels, and the legend stays clean too.
For example, you can update your controller like this:
var rawData = new List<DoughnutChartData>
{
new DoughnutChartData { xValue = "Funerals", yValue = funerals },
new DoughnutChartData { xValue = "Weddings", yValue = weddings },
new DoughnutChartData { xValue = "Regular Weekend", yValue = regularWeekend },
new DoughnutChartData { xValue = "Holy Day", yValue = holyDay },
new DoughnutChartData { xValue = "Other", yValue = other }
};
var chartDataDoughnut = rawData
.Where(x => x.yValue > 0)
.Select(x => new DoughnutChartData
{
xValue = x.xValue,
yValue = x.yValue,
text = ((double)x.yValue / jobsCompleted.Count() * 100).ToString("0.##") + "%"
})
.ToList();
ViewBag.dataSource = chartDataDoughnut;
Once you filter out empty categories, the chart only renders the slice that matters. Your legend will also stay clean, similar to the expense tracker example you mentioned.
A similar approach is often used in event-related dashboards too. In my case, I was checking some data for a wedding ring making workshop, and the chart only became useful once zero-value categories were removed. The same logic applies here. By cleaning the dataset before binding it to the chart, the output looks polished without any extra view-level hacks.
This should give you a simple and reliable fix.
Hi Sam,
Thank you for sharing the approach. Filtering out zero-value categories before binding the data is indeed a clean and effective solution. This ensures the chart and legend remain clear without extra view-level adjustments.
Regards,
Durga Gopalakrishnan.