Solved

I need a transform an int to a Date format to create a High-Low JFreeChart

Posted on 2006-10-26
4
289 Views
Last Modified: 2010-05-18
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,pointer);        
    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("Chart for "+symbol,date,high,low,open,close,volume);
0
Comment
Question by:blarouche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17811520
depends how your int is storing the date :)
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
0
 

Author Comment

by:blarouche
ID: 17811878
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 ?




0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 17811958
DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date d = sdf.parse(Integer.toString(i));
0
 

Author Comment

by:blarouche
ID: 17812111
Excellent

Thank you objects
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question