Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 78072

Manually add categories to categorical axis?

$
0
0
Hi Steve,

The CategoricalAxis uses the series's bound data source to determine the categories to use on the axis (using the property you've set as the series CategoryBinding). It also displays those categories in the order that they are in the bound collection.

If you wanted to have the categories appear in a particular order, you can reorder the bound collection's items and the axis will update accordingly.

Important Note: if your series ItemsSource is bound to a type with item observability, like ObservableCollection<T>, the chart will update as the items change (as seen in my demo). However, if you're using something without observability, like List<T>, you'll need to reset the ItemsSource after sorting.


Alternative

There is another option you can use, the DateTimeCategoricalAxis. With this axis type, it understands the order of the dates and will arrange them in order no matter what order they appear in the bound collection.

To demonstrate this, I've attached a demo app (run the upgrade wizard to restore the Telerik DLLs or update the references manually).

The Chart on the left, ChartOne, is using a model where the category binding is plain string with the "YYYY" as the category:

<telerik:CategoricalAxis />


The Chart on the right, ChartTwo, is using a DateTime as the category, but I set the LabelFormat to only show the YYYY as the label:

<telerik:DateTimeCategoricalAxis LabelFormat="yyyy"/>


Underneath the charts you'll see a button, AddItemButton. Clicking it will add a new item to the chart's data sources. You'll see the charts update in real time and demonstrate how the different Axis types handle the data.

Here's a before and after adding items screenshot:

BEFORE



AFTER




Summary

The takeaway is that you can do one of two things to accomplish what you want:

1 - Sort the data in the bound collection so that it is added to the series in the order you want
2 - Use a DateTimeCategoricalAxis and let the Axis handle the sorting automatically

Please let us know if you have any further questions. Thank you for contacting Support and for choosing Telerik by Progress.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!

Viewing all articles
Browse latest Browse all 78072

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>