Help with Time Series Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
conasdem
Posts: 9
Joined: Thu Jul 27, 2006 6:22 pm
Location: portugal

Help with Time Series Chart

Post by conasdem » Tue Aug 08, 2006 7:56 pm

If you look to my test image, you’ll understand what I want to do.
test Image
For each day I want to see the number of calls made and the total duration for all calls.

The chart is exactly what I wanted, there is only one problem that really needs your help.

If the total duration of calls is more that 24 hours, there will be problems to display.

The time series I use is like this:

Code: Select all

TimeSeries s2 = new TimeSeries("Duration", Day.class);
s2.add(new Day(2,2, 2001), 5000*1000);
s2.add(new Day(3,2, 2001), 3230*1000);
s2.add(new Day(4,2, 2001), 4170*1000);
…..
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s2);
return dataset;
The data is the duration for that day in milliseconds.

The chart is like this

Code: Select all

JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Phone - duration and number of calls plot", 
            "Date", "number of calls", dataset, 
            false, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
Then I add a simple date format to change it to hour minute second.

Code: Select all

DateAxis dateAxisRange = new DateAxis("Time");
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
timeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
plot.setRangeAxis(dateAxisRange ); 
Because it uses a date in the “SimpleDateFormat”, when I have a month (I kwon I have all the code for a day timeserieschart but I also use it for month charts) with more that 24 hours duration it adds a day and only the remaining hour show up. For example with 26hours of duration it only appear in the label 02:00:00

How can I fix this?

I’ll thank in advance for any help :) Goodbye.

cenicienta
Posts: 15
Joined: Mon Jun 26, 2006 8:31 pm
Location: Paris

Post by cenicienta » Wed Aug 09, 2006 3:13 pm

Take a look at this post.

conasdem
Posts: 9
Joined: Thu Jul 27, 2006 6:22 pm
Location: portugal

Tks

Post by conasdem » Wed Aug 09, 2006 6:14 pm

tks for your help. When I searched the forum I didn't use the key word duration.

Could you get me the code for your class DurationFormat, or just the most important bits of code. You would save the trouble of doing that.

Tks a lot again.

bye

conasdem
Posts: 9
Joined: Thu Jul 27, 2006 6:22 pm
Location: portugal

solution

Post by conasdem » Thu Aug 10, 2006 11:49 am

Ok I have the solution based on the other post.

The code for the DurationFormat is:

Code: Select all

package ciscoVoip;

import java.text.FieldPosition;
import java.text.Format;
import java.text.NumberFormat;
import java.text.ParsePosition;

public class DurationFormat extends NumberFormat {

	public DurationFormat() {
		super();
	}

	@Override
	public StringBuffer format(double segundos, StringBuffer arg1, FieldPosition arg2) {
		long remdr =(long)segundos;
		long hours = remdr / ( 60 * 60 );
		remdr = remdr % ( 60 * 60  );
		long minutes = remdr / ( 60);
		remdr = remdr % ( 60 );
		long seconds = remdr ;
		arg1.append(""+hours+":"+minutes+":"+seconds);
		return arg1;
	}

	@Override
	public StringBuffer format(long segundos, StringBuffer arg1, FieldPosition arg2) {
		long remdr =(long)segundos;
		long hours = remdr / ( 60 * 60 );
		remdr = remdr % ( 60 * 60  );
		long minutes = remdr / ( 60);
		remdr = remdr % ( 60 );
		long seconds = remdr ;
		arg1.append(""+hours+":"+minutes+":"+seconds);
		return arg1;
	}

	@Override
	public Number parse(String arg0, ParsePosition arg1) {
		// TODO Auto-generated method stub
		return null;
	}


}
It's in portuguese some words, but i think it's easy to understand.

ok now the axis is like this:

Code: Select all

DurationFormat df=new DurationFormat();
	        NumberAxis numberAxe=new NumberAxis("Duração total (hh:mm:ss)");
	        numberAxe.setNumberFormatOverride(df);
	        
	        plot.setRangeAxis(numberAxe );

Locked