You can do this with the Chart component (chart type = Category Chart), not with the Bar Chart…
In Chart Extension Functions->configureChart insert this code:
# Put your code here
from org.jfree.chart.axis import TickUnits
from org.jfree.chart.axis import DateTickUnit
from java.text import SimpleDateFormat
from org.jfree.chart.renderer.category import StandardBarPainter
from org.jfree.chart.labels import ItemLabelPosition
from org.jfree.chart.labels import ItemLabelAnchor
from org.jfree.ui import TextAnchor
from java.awt import Color
from java.awt import Font
from org.jfree.chart.labels import StandardCategoryItemLabelGenerator
from java.text import NumberFormat
class myLabelGenerator(StandardCategoryItemLabelGenerator):
def generateLabel(self,dataset,series, category):
value = dataset.getValue(series,category)
#print value
if value > 0.0:
return NumberFormat.getInstance().format(int(value))
else:
return None
plot = chart.getPlot()
renderer = plot.getRenderer()
renderer.setBarPainter(StandardBarPainter())
renderer.setShadowVisible(0)
renderer.setBaseItemLabelFont(Font("Roboto Condensed", Font.PLAIN, 12))
renderer.setBaseLegendTextFont(Font("Roboto Condensed", Font.PLAIN, 12));
renderer.setItemLabelGenerator(myLabelGenerator())
renderer.setItemLabelsVisible(True)
size = plot.getCategories().size()
#====== THIS IS THE ROTATING LABEL PART ======================
# 1.57 is 90 degrees in radians
# ItemLabelPosition requires angle in Radians
if size > 10: #if there is more than 10 rows (for me is more than 10 days)
renderer.setBasePositiveItemLabelPosition(ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -1.57))
#===============================================
plot.getDomainAxis().setMaximumCategoryLabelLines(3)
plot.getDomainAxis().lowerMargin = 0.005
plot.getDomainAxis().upperMargin = 0.005
units = TickUnits()
# Format definitions
# Formats are created with default timezone and default locale
# format.setTimezone might be used to override the timezone
# Additional space is added to the format to prevent ticks from being
# displayed without space (hprojectens sometimes when using anchored layout).
formatMSec = SimpleDateFormat(" HH:mm:ss SS")
formatSec = SimpleDateFormat(" HH:mm:ss")
formatMin = SimpleDateFormat(" HH:mm")
formatHour = SimpleDateFormat(" HH:mm")
#formatDay = SimpleDateFormat(" dd. MM. HH:mm")
formatDay = SimpleDateFormat(" dd MMM yyyy")
formatMonth = SimpleDateFormat(" dd MMM yyyy")
formatYear = SimpleDateFormat(" MMM yyyy")
# Add the units
#units.add(DateTickUnit(DateTickUnit.MILLISECOND, 5, formatMSec))
#units.add(DateTickUnit(DateTickUnit.MILLISECOND, 50, DateTickUnit.MILLISECOND, 5, formatMSec))
#units.add(DateTickUnit(DateTickUnit.MILLISECOND, 250, DateTickUnit.MILLISECOND, 50, formatMSec))
#units.add(DateTickUnit(DateTickUnit.MILLISECOND, 500, DateTickUnit.MILLISECOND, 50, formatMSec))
#units.add(DateTickUnit(DateTickUnit.SECOND, 1, DateTickUnit.MILLISECOND, 50, formatSec))
#units.add(DateTickUnit(DateTickUnit.SECOND, 2, DateTickUnit.MILLISECOND, 250, formatSec))
#units.add(DateTickUnit(DateTickUnit.SECOND, 5, DateTickUnit.MILLISECOND, 250, formatSec))
#units.add(DateTickUnit(DateTickUnit.SECOND, 10, DateTickUnit.MILLISECOND, 500, formatSec))
#units.add(DateTickUnit(DateTickUnit.SECOND, 30, DateTickUnit.SECOND, 2, formatSec))
#units.add(DateTickUnit(DateTickUnit.MINUTE, 1, DateTickUnit.SECOND, 5, formatSec))
#units.add(DateTickUnit(DateTickUnit.MINUTE, 2, DateTickUnit.SECOND, 10, formatMin))
#units.add(DateTickUnit(DateTickUnit.MINUTE, 5, DateTickUnit.SECOND, 30, formatMin))
#units.add(DateTickUnit(DateTickUnit.MINUTE, 10, DateTickUnit.MINUTE, 1, formatMin))
#units.add(DateTickUnit(DateTickUnit.MINUTE, 20, DateTickUnit.MINUTE, 5, formatMin))
#units.add(DateTickUnit(DateTickUnit.MINUTE, 30, DateTickUnit.MINUTE, 5, formatMin))
#units.add(DateTickUnit(DateTickUnit.HOUR, 1, DateTickUnit.MINUTE, 5, formatHour))
#units.add(DateTickUnit(DateTickUnit.HOUR, 2, DateTickUnit.MINUTE, 10, formatHour))
#units.add(DateTickUnit(DateTickUnit.HOUR, 4, DateTickUnit.MINUTE, 30, formatHour))
#units.add(DateTickUnit(DateTickUnit.HOUR, 6, DateTickUnit.HOUR, 1, formatDay))
#units.add(DateTickUnit(DateTickUnit.HOUR, 12, DateTickUnit.HOUR, 2, formatDay))
units.add(DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 4, formatDay))
units.add(DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 4, formatDay))
units.add(DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, formatDay))
units.add(DateTickUnit(DateTickUnit.DAY, 14, DateTickUnit.DAY, 1, formatDay))
units.add(DateTickUnit(DateTickUnit.MONTH, 1, DateTickUnit.DAY, 1, formatDay))
units.add(DateTickUnit(DateTickUnit.MONTH, 2, DateTickUnit.DAY, 7, formatMonth))
units.add(DateTickUnit(DateTickUnit.MONTH, 3, DateTickUnit.DAY, 14, formatMonth))
units.add(DateTickUnit(DateTickUnit.MONTH, 6, DateTickUnit.MONTH, 1, formatMonth))
units.add(DateTickUnit(DateTickUnit.YEAR, 1, DateTickUnit.MONTH, 1, formatYear))
units.add(DateTickUnit(DateTickUnit.YEAR, 2, DateTickUnit.MONTH, 3, formatYear))
#chartUtils.setDateTickUnits(chart, "", units = units)
#chartUtils.setDateTickUnits(chart, "", units = units)
#this chartUtils is custom script in project Script library project.chartUtils
project.chartUtils.setDateTickUnits(chart,"", units = units)