Hello
How can I show an operating range in a chart? Actually I’m using 2 horizontal lines, but I would like to color this area instead.
Thanks.
Hello
How can I show an operating range in a chart? Actually I’m using 2 horizontal lines, but I would like to color this area instead.
Thanks.
In theory, something like this script to add a ValueMarker:
But you want to use the IntervalMarker class instead:
https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/IntervalMarker.html
I played around with PGriffith’s suggestion, and I was able to get it to work.
Put this code in the actionPerformed event handler of a button, and it will give you exactly what your asking for:
from java.awt import BasicStroke
from org.jfree.chart.plot import ValueMarker
lowRange = 10
highRange = 20
centerOfRange = (lowRange+highRange)/2
totalRange = 4*(highRange-lowRange)
event.source.parent.getComponent('Chart').chart.plot.addRangeMarker(ValueMarker(centerOfRange, system.gui.color(20, 10, 10, 40), BasicStroke(totalRange)))
If you need this to happen automatically, perhaps fire it from the internalFrameOpened even handler of the parent window
I kept exploring the other related Java options, and I found that I was able to get the same effect with the IntervalMarker extension. The result is exactly the same, but the code is a little bit simpler:
from org.jfree.chart.plot import IntervalMarker
lowSetPoint = 10
highSetPoint = 20
event.source.parent.getComponent('Chart').chart.plot.addRangeMarker(IntervalMarker(lowSetPoint, highSetPoint, system.gui.color(20, 10, 10, 40)))
@justinedwards.jle you mentionned using the internalFrameOpened event handler for automatic config. How about using the Chart’s configureChart Extension Function ? I tried it but nothing happens. Can someone explain why? Maybe I misinterpreted the purpose of this function?
“”"
Provides an opportunity to perform further chart configuration via
scripting. Doesn’t return anything.
Arguments:
self: A reference to the component that is invoking this function.
chart: A JFreeChart object. Refer to the JFreeChart documentation for
API details.
“”"
Knowing that the range must be applied to the second subplot, here is the code used:
from org.jfree.chart.plot import IntervalMarker
lowSetPoint = self.parent.AccumulatorWindowLow
highSetPoint = self.parent.AccumulatorWindowHigh
subplot = self.getChart().getPlot().getSubplots()[2]
subplot.addRangeMarker(IntervalMarker(lowSetPoint, highSetPoint, system.gui.color(255,127,39, 50)))
Try using the chart
object supplied to the routine (and using jython optimized property access):
subplot = chart.plot.subplots[2]
Thanks @pturmel. It's working now!
I really love this forum and the Ignition’s community. Thanks everyone!
Interresting fact I want to share with the community. In our solution the range can change over time. We implemented event handlers on the value of the range’s min and max. If you keep adding ranges over time, colors will also add on top of the others.The range can become opaque even if you want to keep it with a certain level of transparency.
Consider calling .clearRangeMarkers()
before calling .addRangeMarker(...)
When called from within configureChart
it is always a new chart object. No accumulating markers. To accommodate changing ranges, you can subclass the appropriate marker to look up the values in your custom properties every time it is asked instead of supplying a constant in the standard marker.