How to format the pie chart tooltip y value in Blazor Charts?
This article explains how to format the y-value of a pie chart tooltip using an event.
Formatting Tooltip Y Value
Blazor Charts provides an option to format the pie chart tooltip y value using the TooltipRender event. This can be achieved by converting the data point y value from the TooltipRender event arguments using the N3 format and assigning the formatted text to the Text
argument.
The code example below demonstrates how to format a tooltip double value.
Index.razor:
@using Syncfusion.Blazor.Charts
@using System.Globalization;
<div class="control-section">
<SfAccumulationChart EnableSmartLabels="false" EnableBorderOnMouseMove="false" ID="drilldown" >
<AccumulationChartTooltipSettings Enable="true"></AccumulationChartTooltipSettings>
<AccumulationChartEvents TooltipRender="TooltipRenderEvent"></AccumulationChartEvents>
<AccumulationChartLegendSettings Visible="false"></AccumulationChartLegendSettings>
<AccumulationChartSeriesCollection>
<AccumulationChartSeries DataSource="@StatisticsDetails" XName="XValue" YName="YValue" Name="Browser" Radius="@Radius" StartAngle="0"
EndAngle="360" InnerRadius="@InnerRadius">
<AccumulationDataLabelSettings Visible="false">
</AccumulationDataLabelSettings>
</AccumulationChartSeries>
</AccumulationChartSeriesCollection>
</SfAccumulationChart>
</div>
@code{
public string FontColor = "black";
public AccumulationLabelPosition LabelPosition { get; set; } = AccumulationLabelPosition.Inside;
public bool Rotation { get; set; } = false;
public string Radius = "100%";
public string InnerRadius = "0%";
public void TooltipRenderEvent(Syncfusion.Blazor.Charts.TooltipRenderEventArgs args)
{
args.Text = args.Data.PointX + " " + Convert.ToDouble(args.Data.PointY).ToString("N3", CultureInfo.InvariantCulture);
}
public class Statistics
{
public string XValue { get; set; }
public double YValue { get; set; }
}
public List<Statistics> StatisticsDetails = new List<Statistics>
{
new Statistics { XValue = "Chrome", YValue = 374.235423423123 },
new Statistics { XValue = "Firefox", YValue = 273.523423432321 },
new Statistics { XValue = "Opera", YValue = 294.234423421231 },
new Statistics { XValue = "Edge", YValue = 434.233423422312 },
};
}
The following screenshot illustrates the output of the code snippet:
Output:
Live Sample for Tooltip Format
Conclusion:
I hope you enjoyed learning how to format the pie chart tooltip y value in Blazor Chart.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Charts and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!