
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;
}