Sort the Y-Axis using JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
AggressiveFish
Posts: 10
Joined: Wed Apr 18, 2007 8:37 pm

Sort the Y-Axis using JFreeChart

Post by AggressiveFish » Tue Jun 26, 2007 4:15 pm

I was wondering what is the easiest method of displaying the values on the Y-Axis in a JFreeChart line or bar graph in descending order. Any help would be much appreciated.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jun 27, 2007 9:29 am

Code: Select all

axis.setInverted(true);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

AggressiveFish
Posts: 10
Joined: Wed Apr 18, 2007 8:37 pm

Sorting Y-Axis in descending order

Post by AggressiveFish » Thu Jun 28, 2007 8:01 pm

I used the DefaultKeyedValues object to sort them (i.e. dataF.sortByValues(SortOrder.DESCENDING)) and then used DatasetUtilities.createCategoryDataset (for my first series). The second series and first series are set up to have the exact same keys so all is well. Thanks for the post.

AF

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Fri Jun 29, 2007 4:35 pm

OK, I guess by "y-axis" you meant the CategoryAxis?

I'd like to rework the CategoryAxis at some point so that it can control the order of the categories independently of the order that they appear in the dataset. But for now, the order is driven by the dataset, as you've found.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked