java - Displaying all XYSeries at once in jFreeChart for improving speed -
suppose need display multiple xyseries
in single xyseriescollection
. problem every time add xyseries
, jfreechart
wants update chart , slows down process of displaying multiple xyseries
.
what want similar this:
// not update chart xyseriescollection.add(xyseries1) xyseriescollection.add(xyseries2) ... xyseriescollection.add(xyseries10) // update chart
how can this?
construct new xyseriescollection
having desired series, , invoke setdataset()
on xyplot
. generate single datasetchangeevent
.
addendum: here's sscce updates n series, each having n2 values. performance question, example may helpful in profiling.
import java.awt.borderlayout; import java.awt.dimension; import java.awt.eventqueue; import java.awt.event.actionevent; import java.util.random; import javax.swing.abstractaction; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import org.jfree.chart.*; import org.jfree.chart.plot.xyplot; import org.jfree.data.time.day; import org.jfree.data.time.timeseries; import org.jfree.data.time.timeseriescollection; import org.jfree.data.xy.xydataset; public class chartpaneltest { private static final int n = 16; private static final random random = new random(); private static xydataset createdataset() { timeseriescollection tsc = new timeseriescollection(); (int j = 0; j < n; j++) { timeseries series = new timeseries("data" + j); day current = new day(); (int = 0; < n * n; i++) { series.add(current, random.nextgaussian()); current = (day) current.next(); } tsc.addseries(series); } return tsc; } private static jfreechart createchart(final xydataset dataset) { jfreechart chart = chartfactory.createtimeserieschart( "test", "day", "value", dataset, false, false, false); return chart; } public static void main(string[] args) { eventqueue.invokelater(new runnable() { @override public void run() { jframe f = new jframe(); f.setdefaultcloseoperation(jframe.exit_on_close); xydataset dataset = createdataset(); jfreechart chart = createchart(dataset); final xyplot plot = chart.getxyplot(); chartpanel chartpanel = new chartpanel(chart) { @override public dimension getpreferredsize() { return new dimension(600, 300); } }; f.add(chartpanel); jpanel p = new jpanel(); p.add(new jbutton(new abstractaction("new") { @override public void actionperformed(actionevent e) { plot.setdataset(createdataset()); } })); f.add(p, borderlayout.south); f.pack(); f.setlocationrelativeto(null); f.setvisible(true); } }); } }
Comments
Post a Comment