I am having problems with an application I wrote using jfreechart.
I am opening up a file file and reading in 84 sets of data with 1600 data points each.
All of this data stays in memory in 84 DataFile objects which extend Vector<DataPoint> so I can do stuff like this...
Code: Select all
DataFile dataFile = new DataFile();
dataFile.add(new DataPoint(12.5,23.4));
Also, my DataFile class has an XYSeries.
I realize that i am holding on to duplicate data here.
So, the program loads, reads in the file and there are no problems, everything fits into memory.
I hold all datafiles in a JList and when they are selected, they are rendered.
Here is my code for rendering...
This is a in a class that extends JPanel
Code: Select all
public void createChart(){
DataFile data = Global.currentDataFile;
if(data == null)
return;
System.err.println("createChart() : " + data.getName());
// remove the current plot
this.removeAll();
System.gc();
XYSeries series = data.getSeries();
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart(Global.currentDataFile.getName(), "Freq (Hz)", "Real", dataset, PlotOrientation.VERTICAL, true, true, false);
chart.getXYPlot().setRangeZeroBaselinePaint(Color.MAGENTA);
chart.getXYPlot().setRangeZeroBaselineVisible(true);
chart.getXYPlot().getRangeAxis().setLowerMargin(.2);
//chart.getXYPlot().setRangeZeroBaselineStroke(new BasicStroke(2));
// do first with slope = -1, then with slope = +1, then exit the do loop.
int slope = -1;
do{
for(int i = 0 ; i < data.getZeros(slope).size() ; i++){
ZeroCrossing z = data.getZeros(slope).get(i);
if(z.isActivated()){
//System.out.println(z);
XYTextAnnotation t1 = new XYTextAnnotation(String.format("%.2f",z.getZero()),z.getZero(),-1 * data.getAbsMax() - .4);
t1.setRotationAngle(3 * Math.PI / 2);
// vertical line
XYLineAnnotation l1 = new XYLineAnnotation(z.getZero(),-1,z.getZero(),1,new BasicStroke(0.5f),Color.BLUE);
chart.getXYPlot().addAnnotation(t1);
chart.getXYPlot().addAnnotation(l1);
}
}
slope *= -1;
}while(slope != -1);
chart.getXYPlot().getRangeAxis().setAutoRangeMinimumSize(3);
chart.getXYPlot().getRangeAxis().centerRange(0);
ChartPanel cp = new ChartPanel(chart);
this.add(cp,BorderLayout.CENTER);
this.updateUI();
Global.botPane.setUp();
}
Code: Select all
this.removeAll();
System.gc();
Going from chart to chart is real fast when it starts up, then it starts getting slow, then I start getting OutOfMemoryErrors.
Since all data is getting loaded up front and there are no changes to these DataFile Objects and the first 20 or so of them can be displayed without problem, I figured the problem is in my creation of the chart.
Like I said, all data is loaded up front...the only objects being created after the initial startup are these charts.
Any ideas?
The container of the chart is calling this.removeAll();...so would that destroy the chart properly?
Any help is appreciated.
Thanks,
~Eric