How to show axis labels smartly without intersecting in Blazor Chart?
This article explains how to display axis labels without intersecting in the Blazor Chart.
Showing all axis labels in Blazor Chart
By default, the axis labels that intersect with each other will be trimmed. Blazor Chart has options to make all the labels visible and position the collided labels smartly by using LabelIntersectAction property.
The LabelIntersectAction property includes the following customization actions:
- None- Show all labels, regardless of intersections.
- Hide- Hide labels that intersect with each other.
- Trim- Trim labels to fit within the available space when they intersect.
- Wrap- Wrap labels to multiple lines when they intersect.
- MultipleRows- Display labels in multiple rows when they intersect.
- Rotate45- Rotate labels by 45 degrees when they intersect.
- Rotate90- Rotate labels by 90 degrees when they intersect.
In the following code example, the intersect labels are rotated to 45 degrees.
Index.razor
@using Syncfusion.Blazor.Charts
<SfChart Title="Olympic Medals" Width="1000">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category" LabelIntersectAction="LabelIntersectAction.Rotate45"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@MedalDetails" XName="X" YName="Y" Type="ChartSeriesType.Column"/>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double Y { get; set; }
}
public List<ChartData> MedalDetails = new List<ChartData>
{
new ChartData { X= "South Korea", Y= 39 },
new ChartData { X= "India", Y= 61 },
new ChartData { X= "Pakistan", Y= 20 },
new ChartData { X= "Germany", Y= 65 },
new ChartData { X= "Australia", Y= 15 },
new ChartData { X= "Italy", Y= 29 },
new ChartData { X= "United Kingdom", Y= 44 },
new ChartData { X= "Saudi Arabia", Y= 9 },
new ChartData { X= "Russia", Y= 40 },
new ChartData { X= "Mexico", Y= 31 },
new ChartData { X= "Brazil", Y= 75 },
new ChartData { X= "China", Y= 51 }
};
}
The following code snippet illustrates the output of the above code snippet.
Output:
Conclusion
I hope you enjoyed learning how to show axis labels smartly without intersecting 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!