How format date axis axis for bar chart component in Report Module

Hi
There is no option for formatting the date in horizontal axis in bar component in Report module.
I want to show only yyyy/DD/MM and hide time section. How can I do this?

I have the same problem. I would also like to rotate the date 45° or 90°.

1 Like

I enabled scripting and put this code into the def configureChart(data, chart) script:

plot = chart.getPlot()
axis = plot.getDomainAxis()
axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45)

According to JFreeChart this should work but it doesn’t.

2 Likes

I added
from org.jfree.chart.axis import CategoryLabelPositions
and then it worked

I formatted my date in my SQL query. Hopefully the rotate angle script will help you get to date formatting.

3 Likes

I added this script to configure chart. I needed to display the day of week only
the script I used is below, you can chane (EEE) to (dd-MM-yyyy) to get 18-03-2025

	from java.text import SimpleDateFormat
	
	plot = chart.getPlot()
	dataset = plot.getDataset()
	
	inputFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
	outputFormat = SimpleDateFormat("EEEE")
	
	columnCount = dataset.getColumnCount()
	rowCount = dataset.getRowCount()
	
	# Create a new dataset to copy values into, with new keys
	from org.jfree.data.category import DefaultCategoryDataset
	newDataset = DefaultCategoryDataset()
	
	for row in range(rowCount):
	    rowKey = dataset.getRowKey(row)
	    for col in range(columnCount):
	        colKey = str(dataset.getColumnKey(col))
	        value = dataset.getValue(row, col)
	        try:
	            dateObj = inputFormat.parse(colKey)
	            formattedKey = outputFormat.format(dateObj)
	        except:
	            formattedKey = colKey  # fallback
	
	        newDataset.setValue(value, rowKey, formattedKey)
	
	# Set the new dataset
	plot.setDataset(newDataset)

1 Like