How to add a list of names to tooltip text in Blazor Charts?
This article explains how to add a list of names to tooltip text using an event.
Adding list of names to tooltip text
Blazor Charts provides an option to add list of names to the histogram chart series tooltip text using TooltipRender event. This can be achieved by iterating through list of names using foreach loop and appending each name along with br tag to TooltipRender event Text argument.
The below code example demonstrates how to add list of names to tooltip text.
Index.razor
@using Syncfusion.Blazor.Charts
<SfChart Title="Score of Final Examination">
<ChartEvents TooltipRender="TooltipEvent"></ChartEvents>
<ChartArea><ChartAreaBorder Width="0"></ChartAreaBorder></ChartArea>
<ChartPrimaryXAxis Minimum="0" Maximum="100">
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
</ChartPrimaryXAxis>
<ChartPrimaryYAxis Minimum="0" Maximum="6" Interval="2" Title="Number of Students">
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
</ChartPrimaryYAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ExamScores" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Histogram" BinInterval="20" ShowNormalDistribution="true" ColumnWidth="0.99">
<ChartMarker Visible="true" Height="10" Width="10">
<ChartDataLabel Visible="true" Position="Syncfusion.Blazor.Charts.LabelPosition.Top">
<ChartDataLabelFont Color="#ffffff" FontWeight="600"></ChartDataLabelFont>
</ChartDataLabel>
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
<ChartTooltipSettings Enable="true">
</ChartTooltipSettings>
</SfChart>
@code{
public class Data
{
public double Y { get; set;}
public string[] ListOfNames = { "Nelson", "Amir", "Brenda", "Bernard", "Dennis", "Ruben", "Jason", "Lucas", "Caroline", "Denise", "Alexandra" };
}
public List<Data> ExamScores = new List<Data>
{
new Data { Y=5.250},
new Data { Y=7.750},
new Data { Y=8.275},
new Data { Y=9.750},
new Data { Y=36.250},
new Data { Y=46.250},
new Data { Y=56.250},
new Data { Y=66.500},
new Data { Y=76.625},
new Data { Y=80.000},
new Data { Y=97.75}
};
public void TooltipEvent(Syncfusion.Blazor.Charts.TooltipRenderEventArgs args)
{
args.Text += "<br>";
foreach(var name in ExamScores[0].ListOfNames)
{
args.Text += name + "<br>";
}
args.Text += "<br> Count: " + ExamScores[0].ListOfNames.Count();
}
}
The following screenshot illustrates the output of the code snippet.
Output
Live Sample for Adding List of Names to Tooltip
Conclusion
I hope you enjoyed learning how to add list of name to tooltip text in Blazor Chart Component.
You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries 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!