Prevent Easy Chart Plot from Moving

So the simplest way to achieve this is to use the Standard Chart Components Chart Customizer.

  • Add an additional Dataset
  • Add an additional X-Axis
    • Configure the Axis Location to be on the TOP
  • Add an additional Y-Axis
    • Configure the Axis Location to be on the Right
  • Assign the X and Y axis to the dataset in the Dataset Properties Tab

Once you’ve done this all you need to do is generate the two datasets of data and assign them. The new dataset will appear as a custom property on the chart component, you can assign Tag History Bindings to the datasets. No scripting is needed.

Of course you can also accomplish a similar thing with scripting if you so desire, though it is far from trivial.

Here is a sample that assumes you have a dataset property on the parent container of the chart (I used a standard chart component to write the code, but the code will work on an easy chart as well just may need to tweak it to get to the right container). This is by no means a complete solution but it should be enough to get someone started should they really want to use an easy chart with multiple datasets.

from org.jfree.data.xy import DefaultXYDataset
from org.jfree.chart.axis import DateAxis,AxisLocation
from org.jfree.chart import LegendItem
from java.awt import Color
#get a reference to the plot
plot = chart.getPlot()
	
#create a new Dataset to hold the second set of data
newDs = DefaultXYDataset()
#The series data must be an array of length 2 where each element is a double array of the same length
#The date axis uses milliseconds since epoch the system.date.toMillis() function will return this value
seriesData = [[system.date.toMillis(self.parent.data2.getValueAt(row,0)) for row in range(self.parent.data2.rowCount)],[self.parent.data2.getValueAt(row,1) for row in range(self.parent.data2.rowCount)]]
#Add the series data to the dataset and assign the dataset to the plot.
newDs.addSeries('Ouptut Temp',seriesData)
#an index other than 0 must be supplied here otherwise the original dataset will be overwritten
plot.setDataset(1,newDs) 
	
#Add a new domain axis to the plot and map the dataset to it, an index other than 0 must be used for the new Axis
#Cloning the existing DomainAxis makes this a bit simpler
plot.setDomainAxis(1,plot.getDomainAxis(0).clone())
plot.setDomainAxisLocation(1,AxisLocation.TOP_OR_LEFT)
plot.mapDatasetToDomainAxis(1,1)
	
#Add a new range axis to the plot and map the dataset to it, an index other than 0 must be used for the new Axis
#Cloning the existing RangeAxis makes this a bit simpler
plot.setRangeAxis(1,plot.getRangeAxis(0).clone())
plot.setRangeAxisLocation(1,AxisLocation.BOTTOM_OR_RIGHT)
plot.mapDatasetToRangeAxis(1,1)
	
#Add a legend item for the new dataset
legItems = plot.getLegendItems()
newLegItem = LegendItem(newDs.getSeriesKey(0),newDs.getSeriesKey(0),'','',legItems.get(0).getLine(),legItems.get(0).getLineStroke(),Color.red)
legItems.add(newLegItem)
plot.setFixedLegendItems(legItems)
	
#Add a new renderer for the new dataset and change the color
#Cloning the existing XYItemRenderer makes this a bit simpler
r = plot.getRenderer().clone()
r.setSeriesPaint(0,Color.red)
plot.setRenderer(1,r,True)
1 Like