Okay, the issue appears to be that you are using the Dot Renderer, and it appears that for whatever reason, the dot renderer does not honor the isLabelItemVisible
attribute.
Try this:
def configureChart(self, chart):
from org.jfree.chart.labels import StandardXYItemLabelGenerator
from org.jfree.chart.renderer.xy import XYDotRenderer
from java.text import DateFormat
from java.text import NumberFormat
class XYLabeledDotRenderer(XYDotRenderer):
def drawItem(self,g2,state,dataArea,info,plot,domainAxis,rangeAxis,dataset,series,item,crosshairState,p):
self.super__drawItem(g2,state,dataArea,info,plot,domainAxis,rangeAxis,dataset,series,item,crosshairState,p)
orientation = plot.orientation
x = dataset.getXValue(series,item)
y = dataset.getYValue(series,item)
xAxisLocation = plot.domainAxisEdge
yAxisLocation = plot.rangeAxisEdge
transX1 = domainAxis.valueToJava2D(x,dataArea,xAxisLocation)
transY1 = rangeAxis.valueToJava2D(y,dataArea,yAxisLocation)
if self.isItemLabelVisible(series,item):
self.drawItemLabel(g2,orientation,dataset,series,item,transX1,transY1,(y<0.0))
if isinstance(chart.plot.renderer, XYDotRenderer):
chart.plot.renderer = XYLabeledDotRenderer()
renderer = chart.plot.renderer
xFormat = DateFormat.getDateTimeInstance()
yFormat = NumberFormat.getNumberInstance()
renderer.setItemLabelGenerator(StandardXYItemLabelGenerator('{1}',xFormat,yFormat))
renderer.setBaseItemLabelsVisible(True)
What this does is creates a class XYLabeledDotRenderer, which extendes XYDotRenderer. This class provides the added logic to print the labels.
It will only replace the renderer if the current renderer is an instance of XYDotRenderer.
The Area Renderer has a similar issue.
Otherwise the code should work for any renderer that you select.
If needed, it doesn't take much effort to use a similar method to insure that you only print a lable when the data changes, you would just need to know what type of renderer you were going to use in advance. This would help with keeping the chart looking clean.