So, yes, JFreeChart.getPlot() returns an instance of the Plot interface - at the top of the Javadoc for the interface, you can see the known subclasses:
If you drill into the XYPlot - the most common type of plot you'll see in Ignition, aside from CategoryPlots, which back pie charts and bar charts. XYPlot, meanwhile, lists its direct known subclasses:
And then you can see that the CombinedDomainXYPlot has the getSubplots() method.
Or, you can 'back into' things from the other direction: print type(event.source.chart.plot), which should give you the full classname: org.jfree.chart.plot.CombinedDomainXYPlot, which you can then just look up directly via Google/etc.
The reverse-engineering approach is made a lot more palatable/powerful via the use of @pturmel's inspect.py module, which you can find posted on the forums here.
Thanks for the in-depth response! I think that will help a lot for future tracing. Especially the reminder to use print type(). I think iâve had a play with the inspect.py module, maybe iâll have to get more familiar.
It mainly seems to be dealing with Charts that requires more digging into Java than anything else.
I have used a similar script and it works. the other problem that I have is this only add the marker on the default axis (left axis). i need to put a âmarkerâ on the second axis as well. is there a way of setting it on the second axis (right axis)?
I must probably clarify that Iâm using a time series chart instead of a bar chart but should not make a difference or that much of a difference.
I donât want vertical lines. the Filtrate turb (Upper) is correct which is referencing to the left y-axis. only thing that I want extra is the Turb Removal Baseline must use the the right y-axis as reference because the range or scaling will be different on each y-axis.
I was able to accomplish this using an intermediary ratio in the script to translate the coordinates from the left to the right. Here is the sample code:
I want to do a similar shading, except across a date x-axis of an XY Plot, based on the start/end dates of a date slider. I've tried by CategoryMarker and Marker with no luck:
from org.jfree.chart.plot import Marker;
from org.jfree.ui import Layer
I see a few things that need to be corrected in your code in order to accomplish this.
⢠sDate and eDate are assigned date values, but are never used. Instead when the marker is constructed, two unassigned variables startDate and endDate are used.
⢠For this, I believe that the marker you want is actually IntervalMarker, and I don't believe that the ui layer is needed
⢠I don't usually see event.source and self in the same script unless this is being fired from a custom method and an event is passed in.
⢠Also, for an xyPlot, the dates need to be converted to millis
Other than those minor things, the code should run.
Here is the corrected code:
from org.jfree.chart.plot import IntervalMarker
chart = event.source.parent.getComponent("Chart").getChart()#changed self to event.source (if this change was backwards, then reverse it for all instances)
dateRange = event.source.parent.getComponent('Date Range')
startDate = dateRange.startDate.getTime()#changed startDate and endDate to match what's being used to construct the marker
endDate = dateRange.endDate.getTime()#added getTime to convert date to millis
marker = IntervalMarker(startDate, endDate)#switched plot marker to interval marker
marker.setPaint(system.gui.color(10, 10, 10, 40))
chart.plot.addDomainMarker(marker)#Removed layer specification
"Not working" is pretty vague.
Was an error being thrown? Maybe quietly, in the output console?
Was only one of the added markers showing up? If so, which one - the first one you added, or the second?
As the rest of this thread gets into - do you have multiple subplots? Is this a chart in Vision, or Reporting?
What's the exact code you were using to try to add two markers?
Help me help you. The more information you provide, the better.
I don't see any error in the console. Dont have subplots.
here is the code that I implemented:
from org.jfree.chart.plot import ValueMarker
marker = ValueMarker(0) #point on range axis to label
label = 'Avg: '+str(data['average'])[0:5]
marker.setLabel(label)
chart.getPlot().addRangeMarker(marker)
marker1 = ValueMarker(-0.1) #point on range axis to label
label = 'Avg: '+str(data['average'])[0:5]
marker1.setLabel(label)
chart.getPlot().addRangeMarker(marker1)
I am using the bar chart in the report module. Only the first one showed up in the chart.
Are you sure there's no errors in the console window? configureChart was silently failing with your exact script because I didn't have a data key named average. Once I changed those lines, it worked:
def configureChart(data, chart):
from org.jfree.chart.plot import ValueMarker
marker = ValueMarker(4) #point on range axis to label
label = 'Avg:'
marker.setLabel(label)
chart.getPlot().addRangeMarker(marker)
marker1 = ValueMarker(8) #point on range axis to label
label = 'Avg:'
marker1.setLabel(label)
chart.getPlot().addRangeMarker(marker1)