Vision Chart - possible to show minor tick labels on logarithmic axis?

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

3 Likes