7.9 Report Bar Graph JFreeChart Object

image
image

In my Ignition 7.9 report I am using the built in scripting on the bar graph to modify the X-Axis Labels with the JFreeChart object.

	plot = chart.getCategoryPlot()
	#print str(dir(plot.getDomainAxis()))
	xAxis = plot.getDomainAxis()
	print str(xAxis.getCategoryLabelPositions())
	xAxis.setMaximumCategoryLabelLines(100)
	#xAxis.setTickLabelsVisible(False)

On the bar graph I only want every 5th element to have a label for the x axis, from the built-in property editor it does not appear to be doable, does anyone off hand know how to handle this using the JFreeChart object? The xAxis.setTickLabelVisible(False) will completely disable it but the .sertMaximumCategoryLabelLines() will not produce anything regardless of the input.

I don't have the 7.9 reporting module, but looking at your configure chart function, I imagine you could do it this way:

Vision Code
#def configureChart(data, chart):
	for category in xrange(data.rowCount):
		if not category % 5 == 0:
			chart.plot.domainAxis.setTickLabelPaint(data.getValueAt(category, 0), system.gui.color('white'))
		else:
			chart.plot.domainAxis.setTickLabelPaint(data.getValueAt(category, 0), system.gui.color('black'))

Result:

The script simply hides the unwanted labels by changing their colors to match the background.

Edit: Tested in the reporting module and realized the configureChart 'data' property isn't the chart's dataset. Rewriting the code like this worked in my test environment:

#def configureChart(data, chart):
	
	# Retrieve the dataset from the chart (data is not the dataset
	chartData = chart.plot.dataset
	
	# Iterate over each category (column in DefaultCategoryDataset)
	for category in xrange(chartData.columnCount):
		key = chartData.getColumnKey(category)  # Get the column key for this category
		
		# Hide all the labels that are not divisible by 5 by matching its color to the background,
		# ...so only every 5th label is visible
		if category % 5 != 0:
			color = system.gui.color('white')
		else:
			color = system.gui.color('black')
		
		# Set tick label color for this category
		chart.plot.domainAxis.setTickLabelPaint(key, color)