java - Get plots from CombinedDomainXYPlot (and remove them) -
is there way plot list added combineddomainxyplot if don't keep references them?
i'd there plots, work them , possibly remove them compined plot.
this example code adding plots combineddomainxyplot:
// axis dateaxis domainaxis = new dateaxis("date"); // plot container combineddomainxyplot plotcombined = new combineddomainxyplot(domainaxis); // plot 1 xyplot plot1 = new xyplot(); plot1.setdomainaxis(domainaxis); plotcombined.add(plot1); // plot 2 xyplot plot2 = new xyplot(); plot2.setdomainaxis(domainaxis); plotcombined.add(plot2);
update 1:
i've tried code doesn't return plots. it's not reliable.
for (object sp : plotcombined.getsubplots()) { plotcombined.remove((xyplot)sp); }
it method of removing plots correct?
full example code:
import javax.swing.jframe; import org.jfree.chart.axis.dateaxis; import org.jfree.chart.plot.combineddomainxyplot; import org.jfree.chart.plot.xyplot; public class sample27 extends jframe { public sample27() { super("sample27"); // axis dateaxis domainaxis = new dateaxis("date"); // plot container combineddomainxyplot plotcombined = new combineddomainxyplot(domainaxis); // plot 1 xyplot plot1 = new xyplot(); plot1.setdomainaxis(domainaxis); plotcombined.add(plot1); // plot 2 xyplot plot2 = new xyplot(); plot2.setdomainaxis(domainaxis); plotcombined.add(plot2); system.out.println("plot count before: " + plotcombined.getsubplots().size()); (object sp : plotcombined.getsubplots()) { system.out.println("removing subplot: " + sp); plotcombined.remove((xyplot)sp); } system.out.println("plot count after: " + plotcombined.getsubplots().size()); } public static void main(string[] args) { new sample27(); } }
output:
plot count before: 2 removing subplot: org.jfree.chart.plot.xyplot@15615099 plot count after: 1
getsubplots
returns list
containing items - list
copy standpoint uses collections.unmodifiablelist
, returns new list
backed original. iterate on list
, items in fact being removed underlying list
, affecting iteration on collection
.
rather rely on iteration (eg for (object sp : plotcombined.getsubplots())
), loop on array backwards , use index remove item.
for ( int = plotcombined.getsubplots().size() - 1; >= 0; i-- ){ plotcombined.remove((xyplot)plotcombined.getsubplots().get(i)); }
Comments
Post a Comment