Trying to change color for ValueMarker on Bar Chart

Hello!

I am following this forum question here, which shows how to add the valuemarker as well as changing the color of the line.

Although, I am having trouble getting the line to change colors. I am sure it has something to do with the script, just not sure what within it is giving me issues.

	from java.awt import Color
	from org.jfree.chart.plot import ValueMarker
	red = Color(255, 10, 10)
	marker = ValueMarker(26, red) #point on range axis to label
	marker.setLabel("Goal")
	chart.getPlot().addRangeMarker(marker)

This is the chart with that script, but when I remove the from java.awt import Color and red = Color(255, 10, 10) it will populate with the line as intended.

The script for the working one,

	from org.jfree.chart.plot import ValueMarker
	marker = ValueMarker(26) #point on range axis to label
	marker.setLabel("Some Marker")
	chart.getPlot().addRangeMarker(marker)

This is the Bar Chart with working script.
image

Thank you

According to the ValueMarker javadoc, the constructor needs a stroke style as well if you use a paint value in it.

EDIT: You might try the setPaint method on the marker

	from java.awt import Color
	from org.jfree.chart.plot import ValueMarker
	red = Color(255, 10, 10)
	marker = ValueMarker(26) #point on range axis to label
	marker.setPaint(red)
	marker.setLabel("Goal")
	chart.getPlot().addRangeMarker(marker)
1 Like

I did not have the stroke style constructor. After adding that it worked as intended! Thank you!