Articles in this section
Category / Section

How to add a list of names to tooltip text in Blazor Charts?

3 mins read

This article explains how to add a list of names to tooltip text using an event in the Blazor Charts…

Adding a List of Names to Tooltip Text

Blazor Charts provides an option to add a list of names to the histogram chart series tooltip text using the TooltipRender event. This can be achieved by iterating through a list of names using a foreach loop and appending each name along with a br tag to the TooltipRender event’s Text argument.

The code example below demonstrates how to add a 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:

image.png

Live Sample for Adding List of Names to Tooltip

Conclusion:

We hope you enjoyed learning how to add a list of names to tooltip text in the Blazor Chart Component.

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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied