Range axis where 0 is a maximum, but bars start at minimum

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
spatula
Posts: 1
Joined: Sun Oct 01, 2017 6:14 pm
antibot: No, of course not.

Range axis where 0 is a maximum, but bars start at minimum

Post by spatula » Sun Oct 01, 2017 6:24 pm

Scratching my head on this one a little bit.

I want to do a bar chart of values in decibels, where the maximum value is 0, and the range will go from 0 to some small negative number; for example, from 0 to -80.

Inverting the axis is easy enough; however, I still want the bars themselves to start at the *bottom* of the chart and extend *upwards*. In other words, if the minimum value for the chart is -80, the bottom of each bar should be at -80, and the tallest possible bar should extend from the position for value -80 to the top, at 0.

I can kind of get the shape that I want by flipping the values of my data around the minimum value, but this of course results in the wrong values for the labels in the chart (I'll end up with 80 at the top and 0 at the bottom for the labels on the range axis).

So it seems like I need to either affect the way the lines themselves are drawn so they start at the minimum value instead of at 0 (preferred), or affect the way the labels are rendered, so I can mirror the data and then mirror the values displayed on the chart to put 0 back at the top and -80 at the bottom (functional but inelegant).

Any suggestions?

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

Re: Range axis where 0 is a maximum, but bars start at minim

Post by david.gilbert » Mon Oct 02, 2017 4:41 am

If I recall correctly, the setBase(double) method in the BarRenderer class was intended for this type of case:

http://www.jfree.org/jfreechart/api/jav ... se-double-

Try it, I didn't have time to test it myself.
David Gilbert
JFreeChart Project Leader

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

Locked