Edit date format in CategoryChart in Report module

I have not figure out how to edit the date format in CategoryChart in Report module.
Tried to use this script

	from java.text import SimpleDateFormat
	from org.jfree.chart.axis import DateAxis
	from org.jfree.chart.axis.DateAxis import setDateFormatOverride
	plot = chart.getXYPlot()#getPlot()
	axis = plot.getDomainAxis()

But getting error

java.lang.ClassCastException: java.lang.ClassCastException: class org.jfree.chart.plot.CategoryPlot cannot be cast to class org.jfree.chart.plot.XYPlot (org.jfree.chart.plot.CategoryPlot and org.jfree.chart.plot.XYPlot are in unnamed module of loader java.net.URLClassLoader @38a2d98b)
  • Stian

You’re asking the chart for its plot as an XY plot - but it’s a category chart, so that step fails.

Go back to getPlot(), which will give you (some subclass of) CategoryPlot. From that, you would still use getDomainAxis, but you’ll get a CategoryAxis of some kind.

From that object, you’ll need to explore what type it is and what methods is has available. I don’t remember offhand if we provide our own implementation. I’d recommend looking up Phil Turmel’s introspect.py (search here on the forums) to explore the axis object you have.

At a guess, you won’t be able to provide a simple date format override; you’ll have to implement your own label generator or similar class to customize the formatting.

1 Like

That would be the introspect() function in inspect.py.

1 Like