Articles in this section
Category / Section

How to Display Total value on a Stacked Column in Blazor Charts?

4 mins read

Overview

This article explains how to display the total value on top of a stacked column chart and inside the tooltip using Syncfusion Blazor Charts.

To achieve this:

  • Use the SharedTooltipRender event to access the stacked values and append the total to the tooltip content.
  • Set the Position property of the ChartDataLabel to Outer to render the total value on top of the stacked columns.
  • Adjust the vertical position of the label using the OnDataLabelRender event for improved visibility.

Code Example

@using Syncfusion.Blazor.Charts

<SfChart>
   <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
   <ChartEvents OnDataLabelRender="DatalabelRender" SharedTooltipRender="TooltipRenderEvent"></ChartEvents>
   <ChartTooltipSettings EnableMarker=false Enable="true" Shared="true"></ChartTooltipSettings>
   <ChartSeriesCollection>
       <ChartSeries Name="YValue" DataSource="@DataSource" XName="X" DashArray="5,5" Fill="blue" Opacity="0.7" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.StackingColumn">
       </ChartSeries>
       <ChartSeries Name="YValue1" DataSource="@DataSource" XName="X" DashArray="5,5" Fill="green" Opacity="0.7" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.StackingColumn">
           <ChartMarker>
               <ChartDataLabel Visible="true" Name="Total" Position="Syncfusion.Blazor.Charts.LabelPosition.Outer">
                   <ChartDataLabelFont Color="black"></ChartDataLabelFont>
               </ChartDataLabel>
           </ChartMarker>
       </ChartSeries>
   </ChartSeriesCollection>
   <ChartLegendSettings Visible="false"></ChartLegendSettings>
</SfChart>

@code {
   public void TooltipRenderEvent(SharedTooltipRenderEventArgs args)
   {
       args.Text.Add("Total : " + args.Data[1].PointText);
   }
   public class ChartData
   {
       public string X { get; set; }
       public double YValue { get; set; }
       public double YValue1 { get; set; }
       public double Total { get; set; }
   }

   public List<ChartData> DataSource = new List<ChartData>
   {
       new ChartData { X= "USA", YValue= 46, YValue1=56, Total = 102 },
       new ChartData { X= "GBR", YValue= 27, YValue1=17, Total = 44 },
       new ChartData { X= "CHN", YValue= 26, YValue1=36, Total = 62 },
       new ChartData { X= "UK", YValue= 56,  YValue1=16, Total = 72 },
       new ChartData { X= "AUS", YValue= 12, YValue1=46 , Total = 58},
       new ChartData { X= "IND", YValue= 26, YValue1=16 , Total = 42},
       new ChartData { X= "DEN", YValue= 26, YValue1=12 , Total = 38},
       new ChartData { X= "MEX", YValue= 34, YValue1=32, Total = 66},
   };

   void DatalabelRender(Syncfusion.Blazor.Charts.TextRenderEventArgs args)
   {
       args.Location.Y -= 20;
   }
} 

Screenshot

The following screenshot illustrates the output of the above code:

msedge_0FmQ8uyW5V.png

Live Sample

Live Sample – Display total value on top of a stacked column chart and inside the tooltip

Conclusion:

We hope you found this guide helpful in learning How to Display Total value on a Stacked Column in Blazor Charts. For more features, visit our [Blazor Charts feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our [Blazor Charts 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!

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