Articles in this section
Category / Section

How to display the axis labels for all datapoints in WPF Chart (SfChart)?

1 min read

Description: 

Axis labels in WPF Chart (SfChart) are displayed based on intervals that are either calculated internally or defined explicitly. Consequently, not all data points in a series may have corresponding axis labels.

 

Solution:

To ensure that all data points have axis labels, you can create a custom axis by overriding the GenerateVisibleLabels method. Below is an example where a CustomDateTimeAxis class is created, inheriting from DateTimeAxis with an overridden GenerateVisibleLabels method.

XAML

<chart:SfChart.PrimaryAxis>
     <local:CustomDateTimeAxis EnableScrollBar="True" 
LabelRotationAngle="90" LabelFormat="dd/MMM hh:mm"
Header="DateTime"/> </chart:SfChart.PrimaryAxis>

C#

protected override void GenerateVisibleLabels()
{
  List<DateTime> list = new List<DateTime>();
  foreach (var n in (this.DataContext as ViewModel).HeartRate)
  {
     if (!list.Contains(n.Year))
       list.Add(n.Year);
  }
  foreach (var n in list)   {      var position = n.ToOADate();      if (VisibleRange.Inside(position))      {        VisibleLabels.Add(new ChartAxisLabel(n.ToOADate(),  n.ToString(LabelFormat, CultureInfo.CurrentCulture), n.ToOADate()));      }   } }

 Output:

The custom implementation ensures that all data points have axis labels in the WPF Chart.

WPF Chart displays Axis Labels


Conclusion

I hope you enjoyed learning how to display the axis labels for all datapoints in WPF Chart.

You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples 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, Direct-Trac, 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