I’m creating a Classic Chart in Vision (8.1.26) and noticed that when I use the logarithmic axis, the tick labels show only the major ticks labels. It would be nice to show the minor tick labels as well. I did some looking, and am I correct that the jFreeChart in Vision is version 1.0 and doesn’t support minor tick mark control? Anyway around this?
That does look to be correct. I am on version 8.1.48, and the jar is still jfreechart-min-1.0.0.jar
I was able to build a custom Logarithmic Axis that includes labels for all the ticks
Result:
Configure Chart extension function script:
#def configureChart(self, chart):
from java.lang import Math
from java.util import ArrayList
from org.jfree.chart.axis import LogarithmicAxis, NumberTick
from org.jfree.ui import TextAnchor
class LabelAllLogTicksAxis(LogarithmicAxis):
def refreshTicksVertical(self, g2, dataArea, edge):
lowerBound = self.range.lowerBound
upperBound = self.range.upperBound
ticks = ArrayList()
# lowerGuard variable added by rpavlicek to cover cases where the lower bound is less than or equal to zero
lowerGuard = lowerBound if lowerBound > 0 else 1e-10
startingDecade = int(Math.floor(Math.log10(lowerGuard)))
endingDecade = int(Math.ceil(Math.log10(upperBound)))
for decade in xrange(startingDecade, endingDecade):
base = 10.0 ** decade
for multiplier in xrange(1, 10):
value = multiplier * base
# Added to remove a negative label that was appearing below the lower bound
if value < lowerBound or value > upperBound:
continue
# https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/NumberTick.html
# NumberTick(Number number, String label, TextAnchor textAnchor, TextAnchor rotationAnchor, double angle)
ticks.add(NumberTick(value, unicode(value), TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0))
return ticks
plot = chart.plot
oldLogAxis = plot.rangeAxis
newLogAxis = LabelAllLogTicksAxis(oldLogAxis.label)
newLogAxis.range = oldLogAxis.range
plot.rangeAxis = newLogAxis
Edit: Added lower guard variable developed by @rpavlicek that covers cases where the lower bound of the chart is less than or equal to zero
Thank you for providing this, I do however get an error: “Error Drawing Chart” - “OverflowError: cannot convert float infinity to long” on these lines:
startingDecade = int(Math.floor(Math.log10(lowerBound)))
endingDecade = int(Math.ceil(Math.log10(upperBound)))
If I change the two int to float, I get the same error on a different line:
for decade in xrange(startingDecade, endingDecade):
I’m trying to work through this now to resolve. Might be a None type or negative that’s messing with it.
You cannot have a lower bound of zero on a logarithmic scale. That makes negative infinity. (Nor any negative lower bound.)
The error is intrinsic--it's fundamental math.
Yes, I put a safe guard in place and works great. Thanks to @justinedwards.jle !
lowerGuard = lowerBound if lowerBound > 0 else 1e-10
startingDecade = int(Math.floor(Math.log10(lowerGuard)))
endingDecade = int(Math.ceil(Math.log10(upperBound)))

