Bar Chart Legend Issue

I have a bar chart component that has a client tag bound to the background color of the chart itself. Using a propertyChange script, I’m changing the background color of the bar chart legend to the same color as the background of the chart (for some reason these aren’t the same by default). The issue I run into is that this works just fine initially, but as soon as the data is updated it changes back to the default white background color. I’m a little confused as to why this happens when I only set the color once. Here’s the propertyChange script.

if event.propertyName == "componentRunning"
	chart = event.source.getChart()
	plot = chart.getPlot()
	plotColor = plot.getBackgroundPaint()
	legend = chart.getLegend()
	legend.setBackgroundPaint(plotColor)

instead of componentRunning try using “data” or whatever your dataset is called.

I’ve done this but as the data updates the legend color flashes momentarily from white to grey (the color I’m trying to set it to). Ideally I’d like to just set the color and have it stay that color without flashing.

Switch over the the regular chart and set it to display bars. Then put your code in the configureChart extension function.

I might be missing something but I’m not seeing a “Bar” chart type for the standard chart component. Part of the reason I’m currently using the bar chart component is that I want horizontal, layered bars. Is this available on any other components? If not is there any plan to add the configureChart extension function to all chart components in the future?

Can you post a screenshot of the bar chart format you want?

Yeah you bet, here’s what I currently have.

1 Like

Put a regular chart and set the chart type to Category Chart.
Create a category X-Axes and set the x-axes to it.

Then put

	from java.awt import Color
	
	plot = chart.getPlot()
	plotColor = plot.getBackgroundPaint()
	legend = chart.getLegend()
	legend.setBackgroundPaint(plotColor)
	
	renderer = plot.getRenderer()
	

	renderer.setSeriesBarWidth(0, 1.5)
	renderer.setSeriesBarWidth(1, .5)

That worked perfectly, thank you! It took me a little bit of experimenting with the Chart component to get it all configured correctly, but I was able to create a chart that looked identical to the one I posted previously with the functionality I was after.