How to Create a Tornado Chart in Blazor Chart?
This article explains how to create a tornado chart in the Blazor Chart component.
Creating a Tornado Chart using Stacked Bar
The Blazor Chart provides support for displaying data points as a tornado chart by utilizing the Stacked Bar chart. This involves providing positive and negative values for Y to render as a tornado chart.
To modify the label of the negative stack axis to appear positive, you can use the OnAxisLabelRender event’s Text
argument. This event triggers before the axis label is rendered.
The following properties are available in the AxisLabelRenderEventArgs:
-
LabelStyle – Specifies the font information of the axis label.
-
Text – Specifies the text to be displayed in the axis label.
-
Value – Specifies the value of the axis label.
The following code example illustrates this:
Index.Razor
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="4.4" Interval="0.2"></ChartPrimaryXAxis>
<ChartEvents OnAxisLabelRender="AxisLabelRenderEvent"></ChartEvents>
<ChartSeriesCollection>
<ChartSeries ColumnWidth="0.5" DataSource="@ChartPoints" XName="Height" YName="Female" Name="Female" Type="ChartSeriesType.StackingBar">
<ChartMarker>
<ChartDataLabel Visible="true" Position="LabelPosition.Top" Name="Female_Text">
<ChartDataLabelFont FontWeight="600"></ChartDataLabelFont>
</ChartDataLabel>
</ChartMarker>
</ChartSeries>
<ChartSeries ColumnWidth="0.5" DataSource="@ChartPoints" XName="Height" YName="Male" Name="Male" Type="ChartSeriesType.StackingBar">
<ChartMarker>
<ChartDataLabel Visible="true" Name="Text" Position="LabelPosition.Top">
<ChartDataLabelFont FontWeight="600"></ChartDataLabelFont>
</ChartDataLabel>
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class StackedBarChartData
{
public string Height { get; set; }
public double Female { get; set; }
public double Male { get; set; }
public string Text { get; set; }
public string Female_Text { get; set; }
}
public string Width { get; set; } = "90%";
public List<StackedBarChartData> ChartPoints { get; set; } = new List<StackedBarChartData>
{
new StackedBarChartData { Height = "4.5", Female = 31, Male = -31, Text = "31 KG", Female_Text = "31 KG" },
new StackedBarChartData { Height = "4.8", Female = 37, Male = -39, Text = "39 KG", Female_Text = "37 KG" },
new StackedBarChartData { Height = "5.1", Female = 49, Male = -52, Text = "52 KG", Female_Text = "49 KG" },
new StackedBarChartData { Height = "5.4", Female = 57, Male = -64, Text = "64 KG", Female_Text = "57 KG" },
new StackedBarChartData { Height = "5.7", Female = 63, Male = -70, Text = "70 KG", Female_Text = "63 KG" },
new StackedBarChartData { Height = "6", Female = 69, Male = -74, Text = "74 KG", Female_Text = "69 KG" }
};
private void AxisLabelRenderEvent(AxisLabelRenderEventArgs args)
{
args.Text = args.Text.Contains("-") ? (args.Text.Replace("-", "")) : args.Text;
}
}
The following screenshot illustrates the output of the above code snippet.
Output:
Conclusion
I hope you enjoyed learning how to create a tornado chart in the 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!