Zooming problems with LogaritmicAxis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jmog

Zooming problems with LogaritmicAxis

Post by jmog » Tue Nov 29, 2005 11:29 am

Hi, I have an XYLineChart with both domain and range axis set to logarithmic and the problem is that when I'm zooming in the correct area doesn't show up. Also when zooming out the zoom probably calls setAutoRange(true) which loses the range I've set. Does anyone have any workarounds or is this behaviour about to be fixed before the release of 1.0.0?

Code: Select all

import javax.swing.*;
import java.awt.*;

import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.axis.LogarithmicAxis;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.*;
import org.jfree.data.xy.*;

public class LogarithmicTest {
	
	ChartPanel chartPanel;
	JFreeChart chart;		
	AbstractXYDataset xyDataset;
	
	public void test() {
		
		XYSeries series1 = new XYSeries("New Series");
		XYSeries series2 = new XYSeries("Assay2");
		
		series1.add(20.0, 10.0);
		series1.add(40.0, 20.0);
		series1.add(70.0, 50.0);
		series1.add(80.1, 35.2);
		
		series2.add(10.0, 15.0);
		series2.add(35.0, 25.0);
		series2.add(67.0, 47.0);
		series2.add(83.1, 30.2);
		
		XYSeriesCollection data = new XYSeriesCollection();
		data.addSeries(series1);
		data.addSeries(series2);
		xyDataset = data;
		
		chart = ChartFactory.createXYLineChart(
				"MyLogartihmicChart",
				"X",           
				"Y",           
				xyDataset,
				PlotOrientation.VERTICAL,
				false,
				false,
				false);
		
		LogarithmicAxis logX = new LogarithmicAxis("X");
		logX.setRange(new Range(1,90));
		LogarithmicAxis logY = new LogarithmicAxis("Y");
		logY.setRange(new Range(1,55));
		
		chart.getXYPlot().setRangeAxis(logY); // Y
		chart.getXYPlot().setDomainAxis(logX); //X
		
		StandardXYItemRenderer rr = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
		rr.setPlotImages(true);
		chart.getXYPlot().setRenderer(rr);
		
		chartPanel = new ChartPanel(chart);
		chartPanel.setMouseZoomable(true);
		
		JFrame frame = new JFrame("JFreeChartTest");
		frame.setLayout(new BorderLayout());
		frame.setSize(600, 450);
		frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
		frame.setVisible(true);
	}
	
}

mst
Posts: 3
Joined: Thu Jul 07, 2005 11:49 am

Post by mst » Wed Nov 30, 2005 3:54 pm

I've posted the source of an extended numeric axis on Sourceforge, which handles arbitrary transformations (Log/sqr/sqrt) and zooms accordingly.

http://sourceforge.net/tracker/index.ph ... tid=315494

regards
Markus

berth
Posts: 2
Joined: Wed Mar 15, 2006 10:54 am

Fix for LogarithmicAxis zoom

Post by berth » Wed Mar 15, 2006 10:58 am

I have posted a subclass that fixes the zoom problem at

http://sourceforge.net/tracker/index.ph ... tid=115494

Locked