Blogs

Bryan Wood - DevExpress Charts Blog

information and training regarding all things DevExpress Charting.

ASP.NET and WinForms Charting - Series and Axis Label Enhancements

     

Overlapping-Axis-Labels

Are your labels crowded? Sometimes the reality is that you have more label than you have room for. Coming in DXperience 2011 volume 1 is a new way to deal with long axis and series labels. Currently if you have a long axis label you have a couple of options. Probably the easiest and most effective would be to change the data, just shorten the names. While this sounds good, in practice or in most business apps I’ve worked on changing the data is not an options. Also if you are tied to a Pivot Grid at may not be an option at all.

A second option would be to rotate the axis label so that width wouldn’t cause you overlap.

Axis-Label-Vertical

For a majority of scenarios this is an acceptable way to avoid overlapping labels. Depending on your layout this may not be a viable option.

Another option would be to stagger your axis labels.

Axis-Labels-Staggered

This is another option that will work in a lot of scenarios but may not work on all of them.

Let’s look at our new options…

New Option

In DXperience 2011 volume 1 we are introducing two new properties on the Axis and Series Labels. The first property is MaxWidth which allows you to set the maximum label width (in pixels), the side effect of having a fixed width is that anything longer than the specified width is wrapped to a new line. The second property is MaxLineCount, which allows you to define the maximum number of lines to allow when wrapping text (0 being unlimited).

Property-Window-ASP.NET-Labels-Enhancement

Lets look at how we can use these new properties. If we just adjust the MaxWidth and set it to 70.

WinForms-and-ASP.NET-Label-ENhancements

Awesome, now we have a way to tame long labels without changing the orientation or staggering. As you can see this makes for a very readable set of axis labels.

Now let’s look at the second property MaxLineCount as I mentioned earlier this limits the number of lines we allow the label to wrap to. In the example below I’ve set the MaxLineCount to 1, meaning that we aren’t going to allow for any line wraps.

Series-and-Axis-Label-Enhancement-Ellipses

You’ll notice that the text that goes beyond the specified width is truncated and an ellipsis is added. These two options in addition to the already existing label options give you an immense amount of control over how you choose to display your labels.

We do sacrifice immediate readability in the truncated chart. A simple way to enhance readability without impacting the layout of the chart would be to use Hit Testing to show the full text when the mouse is hovered over an individual axis label. 

While all of my above samples are using axis labels, these new properties are also give you the ability to have multi-line series labels as well.

Conclusion

As an added benefit these new properties also give you a way to dynamically handle the axis labels when resizing a chart, simply adjust the Max Width and Max Line Count parameters based on the width/height of the chart.

This and other exciting new features are found in DXperience 2011 volume 1 coming soon!

Tell me what you think of this feature in the comments below!

Published May 18 2011, 12:14 PM by Bryan Wood (DevExpress)
Filed under: , , ,
Technorati tags: WinForms, ASP.NET, v2011.1, Charts
Bookmark and Share

Comments

 

Kendall Miller said:

Outstanding! We'd previously gone to some length to implement this in a very approximate way, but your solution looks much nicer.

May 18, 2011 3:37 PM
 

Steve Sharkey said:

Very nice BUT as you've hinted at hit testing couldn't this be a "built-in" option to have the full text appear?

May 19, 2011 3:37 AM
 

Bryan Wood (DevExpress) said:

Kendall: I know, you saved me from a phone call. I knew this would be of interest.

Steve: good question, and because it would be so easy to implement it made more sense to leave the platform open so someone could adjust and display in a way that fit within the application. It would have been difficult to come up with an implementation that would have pleased everyone.

May 19, 2011 11:38 AM
 

Tom Bushell said:

WRT to built in hit testing - I think most developers (and users) would be happy with a default behavior showing the full label as a tooltip.  XtraGrid works this way for narrow columns, and I think it's a great approach.

For those that had special requirements, perhaps "custom" events could be used.

June 3, 2011 11:32 AM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.