I have a simple bar chart in a report I am using SQL to fill the chart. I need a “static” line at a certain value to use as a straight “max” line. I can draw a line, but as the scale of the chart changes dynamically, the line is no longer where it is supposed to be. Is there some code I could add to the chart to position the line appropriately? Or some other method?
Untested, but you would need something like this in the chart configuration script:
from org.jfree.chart.plot import ValueMarker
marker = ValueMarker(123) #point on range axis to label
marker.setLabel("Some Marker")
chart.getPlot().addRangeMarker(marker)
That worked (of course)…my next question is are there other properties I can set for the marker, where can I learn about them? I only need line weight and color!
Paint is a base Java class that's implemented by Color, so you can just use system.gui.color(r, g, b).
Stroke is easiest to define with the BasicStroke class - so just import that class, and use a new instance in the call when you create a new ValueMarker instance.
Add a getChart() after getComponent("Bar Chart") - getComponent gives you the Ignition component, from which you need to getChart() to get the underlying JFreeChart object.
This is working well in my dashboards. On the reports, which is where I first got it working, the reference line shows up in the preview in the report module, but not in the PDF when the report is emailed. Everything else renders in the PDF as expected.
Any ideas what’s preventing the line from rendering in the PDF?
The code is:
from java.awt import BasicStroke
from org.jfree.chart.plot import ValueMarker
goal = 0.5
How can you get this to work on a Chart component that has sub plots?
I have managed to get it working when i only have one dataset, but i’ve got another component with two datasets on different plots.
I’d like to add a different marker to each plot. I’ve tried calling: plot = event.source.getChart().getPlot()
But i suspect there needs to be a way to tell it which plot im interested in? Strangely i’m not getting any marker showing up, nor any errors.
If getPlot() returns a org.jfree.chart.plot.CombinedDomainXYPlot (you can import that class and check isinstance), then it will have a getSubplots() method that returns, naturally, the subplots, which is where you want to actually apply your markers.
Thanks, that worked a treat. I did try and look at the JFree chart docs before posting a question, but i don’t seem to be very good at navigating it. For instance i thought getPlot() returned “org.jfree.chart.plot”, and i was looking at those methods, which doesn’t have getSubplot().
Could you give me a hint of how you traced that out?