LogAxis setRange() function sends me into memory error

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
paololim
Posts: 11
Joined: Tue Jul 17, 2007 3:08 pm
Location: Hopewell Junction, NY

LogAxis setRange() function sends me into memory error

Post by paololim » Wed Feb 06, 2008 4:48 pm

Below is code that sends me into a memory error. I tried calling a simple setRange() function for the LogAxis class. It is important to note that I have never gotten a memory error like this before when working with any sort of axis, except this one.

Here is the error:

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Here is the code:

Code: Select all

import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class Demo extends ApplicationFrame {

    public Demo(String title) {
        super(title);
        JPanel chartPanel = createDemoPanel();
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
    }

    private static JFreeChart createChart(XYDataset dataset) {
        JFreeChart chart = ChartFactory.createScatterPlot("Log Axis Demo 1", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
        XYPlot plot = (XYPlot)chart.getPlot();
        
        LogAxis xAxis = new LogAxis("X");
        plot.setDomainAxis(xAxis);
        
        LogAxis yAxis = new LogAxis("Y");
        yAxis.setRange(0, 100); // causes a really mysterious error!!!
        plot.setRangeAxis(yAxis);

        return chart;
    }

    private static XYDataset createDataset() {
        XYSeries series = new XYSeries("Random Data");
        series.add(1.0, 500.2);
        series.add(5.0, 694.1);
        series.add(4.0, 100.0);
        series.add(12.5, 734.4);
        series.add(17.3, 453.2);
        series.add(21.2, 500.2);
        series.add(21.9, 9005.5);
        series.add(25.6, 734.4);
        series.add(3000.0, 453.2);
        return new XYSeriesCollection(series);
    }

    public static JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart);
    }

    public static void main(String[] args) {
        Demo demo = new Demo("Log Axis Demo 1");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }
}

Wetzerk
Posts: 14
Joined: Thu Feb 07, 2008 3:54 pm

Post by Wetzerk » Thu Feb 07, 2008 4:26 pm

Um, try and enter log(0) in your calculator. It can't do it either.


Try putting a positive number in there and it should work.

Locked