Help me about Time Series

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
comir
Posts: 8
Joined: Sat Jun 16, 2012 3:55 am
antibot: No, of course not.
Location: Indonesia
Contact:

Help me about Time Series

Post by comir » Tue Jun 26, 2012 10:15 am

Image

hello all, as shown in the picture above that the value of the minutes 37 and 38 do not exist. I would ask how to fill the value in minutes 37 and 38 with the value 36 , while data from the database is not sorted. for example data from the database only at minute 36 and 39. What's the solution to be filled with data before it until 15 o'clock. My code is as below:

Code: Select all

private static XYDataset createDataset(){
		
		MysqlDataSource dataSource = new MysqlDataSource();
		dataSource.setUser("root");
		dataSource.setPassword(" ");
		dataSource.setPort(3306);
		dataSource.setDatabaseName("latihan");
		dataSource.setServerName("localhost");
			
		ServiceJdbc service = new ServiceJdbc();
		service.setDataSource(dataSource);
		double tmp = 0;
		
		TimeSeries s0= new TimeSeries("Now");
		TimeSeries s1 = new TimeSeries("Previous");
		TimeSeriesCollection dataset = new TimeSeriesCollection();
		
		s0.add(new Second(CommonUtils.createDate2("090000")), 0);
		s0.add(new Second(CommonUtils.createDate2("160000")), 0);
		
		List<Price> harga = service.getPrice();
			for(Price p : harga){
                                //data fom database
				String tgldb = p.getDate();
				Double price = p.getPrice();
								
				if ((price != 0.0) && price != null) {
					s1.add(new Second(CommonUtils.createDate2(tgldb)),price);
					tmp = price;
				} else {
					price = tmp;
					s1.add(new Second(CommonUtils.createDate2(tgldb)), price);
				}
			}
			
		tmp=0;
		dataset.addSeries(s0);
		dataset.addSeries(s1);
		dataset.setXPosition(TimePeriodAnchor.MIDDLE);
		return dataset;
	}
The data from the database of type String date with format like this "HHmmss". CommonUtils.createDate2 is method to convert from String to integer and inserted to Date type.

flink
Posts: 3
Joined: Mon Feb 13, 2006 12:01 pm
Location: Portugal
Contact:

Re: Help me about Time Series

Post by flink » Tue Jun 26, 2012 12:30 pm

Hi!

If you want minute 37 and 38 to have the same value as 36, you can simply use the XYStepRenderer. Create your renderer, set it up (paint, stroke, ...), and add it to your XYPlot.

P.S.: Unless you have *very* specific and strong reasons to use that color scheme, you really need to sort it out; it looks like CGA palette 1 all over again for me! :mrgreen:

Have fun!

comir
Posts: 8
Joined: Sat Jun 16, 2012 3:55 am
antibot: No, of course not.
Location: Indonesia
Contact:

Re: Help me about Time Series

Post by comir » Wed Jun 27, 2012 2:45 am

Are you able to provide / write full code for me because I have not mastered the JFreeChart or java. :o :)

Locked