blarouche
asked on
I need a transform an int to a Date format to create a High-Low JFreeChart
Hi experts,
I am creating a new class to create stock charts.
My problem comes when I am trying to create a dataset from the class DefaultHighLowDataset.
I need a Date format in the constructor but my date data is express as an int in my list.
What can I do ?
private void execute(){
/**
* Loads Daily Prices
*/
price = conf.getPrices(symbol,poin ter);
if (price.getSize()==0){
System.out.println("No quotes founds for symbol "+symbol+", system can't works.");
System.exit(1);
}
high = new double[price.getSize()];
low = new double[price.getSize()];
close = new double[price.getSize()];
open = new double[price.getSize()];
date = new int[price.getSize()];
volume = new double[price.getSize()];
for (int i=price.getFirst();i<price .getLast() +1;i++){
high[i] = price.getHigh(i);
//System.out.println(price .getHigh(i ));
low[i] = price.getLow(i);
//System.out.println(price .getLow(i) );
close[i] = price.getClose(i);
//System.out.println(price .getClose( i));
open[i] = price.getOpen(i);
//System.out.println(price .getOpen(i ));
date[i] = price.getDate(i);
//System.out.println(price .getDate(i ));
volume[1] = price.getVolume(i);
}
final DefaultHighLowDataset dataset = new DefaultHighLowDataset("Cha rt for "+symbol,date,high,low,ope n,close,vo lume);
I am creating a new class to create stock charts.
My problem comes when I am trying to create a dataset from the class DefaultHighLowDataset.
I need a Date format in the constructor but my date data is express as an int in my list.
What can I do ?
private void execute(){
/**
* Loads Daily Prices
*/
price = conf.getPrices(symbol,poin
if (price.getSize()==0){
System.out.println("No quotes founds for symbol "+symbol+", system can't works.");
System.exit(1);
}
high = new double[price.getSize()];
low = new double[price.getSize()];
close = new double[price.getSize()];
open = new double[price.getSize()];
date = new int[price.getSize()];
volume = new double[price.getSize()];
for (int i=price.getFirst();i<price
high[i] = price.getHigh(i);
//System.out.println(price
low[i] = price.getLow(i);
//System.out.println(price
close[i] = price.getClose(i);
//System.out.println(price
open[i] = price.getOpen(i);
//System.out.println(price
date[i] = price.getDate(i);
//System.out.println(price
volume[1] = price.getVolume(i);
}
final DefaultHighLowDataset dataset = new DefaultHighLowDataset("Cha
ASKER
My date is stored as yyyymmdd.
Now I have a list of int :
for (int i=price.getFirst();i<price .getLast() +1;i++){
date[i] = price.getDate(i);
}
How do I transform this list of int into Date format. Another loop ?
Now I have a list of int :
for (int i=price.getFirst();i<price
date[i] = price.getDate(i);
}
How do I transform this list of int into Date format. Another loop ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent
Thank you objects
Thank you objects
if its using something like 20061206, then use a SimpleDateFormat to parse it (after converting it to a string)
http://javaalmanac.com/egs/java.text/ParseDate.html