Overlapping labels of range axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Narayan
Posts: 30
Joined: Wed Apr 11, 2007 11:20 am
Location: Bangalore

Overlapping labels of range axis

Post by Narayan » Sun May 27, 2007 1:47 pm

Hi,

If my dataset has the values from 0 to 23412345623, then the labels ( indicating the numbers ) overlap with each other.
How can I go about it.

I tried creating my own unit using NumberTickUnit
TickUnitSource rangeUnits = units.add(new NumberTickUnit((maxValue - minValue) / 10)); // minValue is the minmum value and maxValue is the maxValue that appears in the graph.
rangeAxis.setStandardTickUnits(rangeUnits);

But then the not even a single label appeared in the y- axis. Can you please help me out in this.

Regards,

Narayan
Posts: 30
Joined: Wed Apr 11, 2007 11:20 am
Location: Bangalore

Post by Narayan » Mon May 28, 2007 10:59 am

I got the answer.

The labels in the range axis were overlapping because I was using the following line.

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

So when the range was much more than the maximum size of int, the labels in the range axis were overlapping.

Narayan
Posts: 30
Joined: Wed Apr 11, 2007 11:20 am
Location: Bangalore

Post by Narayan » Thu Jun 21, 2007 10:56 am

Hello,

This problem is back.

So I am appending the sample code where the tick labesl of y axis are overlpped.

Code: Select all

package com.jpmchase.mm.application.emb.stats.test;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class ChartHelper2 {
	
	private TimeSeriesCollection createDataset(){
		TimeSeriesCollection dataset = new TimeSeriesCollection();
		
		TimeSeries time = new TimeSeries("", Day.class);
		Day day;
		try {
			day = new Day(new SimpleDateFormat("ddMMyyyy").parse("01052007"));
			time.add(day, 12);
			day = new Day(new SimpleDateFormat("ddMMyyyy").parse("02052007"));
			time.add(day,4);
			day = new Day(new SimpleDateFormat("ddMMyyyy").parse("03052007"));
			time.add(day, Long.parseLong("123456789012345"));
			dataset.addSeries(time);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dataset;
	}
	
	private JFreeChart createChart(TimeSeriesCollection dataset)
	{
		final JFreeChart chart = ChartFactory.createTimeSeriesChart(
				"Title",  // Chart Title
				"X - Axis", // X-Axis Label
				"Y - Axis",        // Y-Axis Label  
				dataset,     // Dataset
				true,        // Show Legend
				true,        // Show Tooltip
				false);      // UR
		
		chart.setBackgroundPaint(Color.white);
		return chart;
	}
	
	public static void main(String [] args){
		ChartHelper2 chartHelper = new ChartHelper2();
		
		TimeSeriesCollection dataset = chartHelper.createDataset();
		JFreeChart chart = chartHelper.createChart(dataset);
		
		try {
			ChartUtilities.writeChartAsPNG(new FileOutputStream("E:\\second.png"), chart, 650, 220);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
Can you please let me know how can I go about soon since its urgent for me.

Regards,
Narayan

Narayan
Posts: 30
Joined: Wed Apr 11, 2007 11:20 am
Location: Bangalore

Post by Narayan » Thu Jun 21, 2007 4:29 pm

Hi All,

It worked ...

I am getting the difference between the minimum and maximum values and deviding by 9 ( number of ticks I want in the range axix) and then setting the tick unit.

Code: Select all

double minValue = (double) rangeAxis.getRange().getLowerBound();
		double maxValue = (double) rangeAxis.getRange().getUpperBound();
		double difference = maxValue - minValue;
		double tickDiff = difference / 9;

rangeAxis.setTickUnit(new NumberTickUnit(tickDiff));
Cheers,
Narayan

Locked