basic java question

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Edward Pottasch

basic java question

Post by Edward Pottasch » Sun May 05, 2002 7:23 am

hope someone has some time to explain some fundamentals to me since I'm learning Java with only help of books and examples I can find. I manage to make charts but don't understand some aspects of Java (so it seems).


I create a HighLowDataset:

// get the data
HighLowDataset hlData = this.createMyHighLowDataset();


where createMyHighLowDataset():


public HighLowDataset createMyHighLowDataset() {
return new MyHighLowDataset(readwritedatafile.getDatumJFree(),
readwritedatafile.getDataJFree("Open"),
readwritedatafile.getDataJFree("High"),
readwritedatafile.getDataJFree("Low"),
readwritedatafile.getDataJFree("Close"),
readwritedatafile.getDataJFree("Volume"),
readwritedatafile.getFileName());
}




MyHighLowDataset is similar to HighLowDataset.java except that I provide the data using a constructor:

public MyHighLowDataset(Date[] adates, Double[] aopens, Double[] ahighs, Double[] alows,
Double[] acloses, Double[] avolumes, String afileName) {
this.dates = adates;
this.opens = aopens;
this.highs = ahighs;
this.lows = alows;
this.closes = acloses;
this.volumes = avolumes;
this.fileName = afileName;
}




and the method getItemCount is changed:

public int getItemCount(int series) {
return closes.length; // one series with 47 items in this sample
}


It works fine but ....my question is: how do my data get into hlData. The methods to return the data are defined in MyHighLowDataset, which implements the interface HighLowDataset. I don't see any calls to these methods. Is this inherent behaviour for interfaces or am I missing something .... it seems that the number of series and the number of items are asked for somehow and all is done for me .... it's like magic ....

thanks for any clarifications,

Edward

Michael T

Re: basic java question

Post by Michael T » Mon May 06, 2002 8:24 pm

I'm not sure what your exact question is. Are you wondering if your implementation is okay? Or just how the jfreechart extracts info from your class? Or how interfaces work?

I would suggest looking at the code behind the plot and renderer classes. Since you are using HighLow then I believe that the appropriate classes would be com.jrefinery.chart.HighLowRenderer and com.jrefinery.chart.XYPlot. That is where the data is extracted to generate the chart.

As for interfaces, I would suggest looking at the java.sun.com tutorials.

http://java.sun.com/docs/books/tutorial/

In particular:

http://java.sun.com/docs/books/tutorial ... faces.html

Finally, the forums and java.sun.com are a good resource. More often than not, searching the forums will find the answer you are looking for.

http://forums.java.sun.com/

And of course, google is a great place to search. google groups also.

Edward

Re: basic java question

Post by Edward » Mon May 06, 2002 9:17 pm

ok, thanks. I will have a closer look tomorrow. Just got back .....

David Gilbert

Re: basic java question

Post by David Gilbert » Tue May 07, 2002 9:03 am

Hi Edward,

As Michael pointed out above, the data is accessed via the interface methods in the HighLowRenderer object (specifically the drawItem(...) method), or another renderer if you are drawing a different kind of chart.

The dataset interfaces in JFreeChart only specify methods for getting data OUT of a dataset, since that's all the charts need to do. How you get data IN is completely up to you, if you write your own dataset class. If you just use an existing dataset class (like TimeSeriesCollection) then you need to look through the API documentation to see what methods are provided for adding and removing data.

Hope that helps,

DG.

Edward

Re: basic java question

Post by Edward » Tue May 07, 2002 2:22 pm

thanks for your reply Dave. In the coming week I'm looking into it again. My charts are already starting to look real nice. It is worth all the efforts,

rgds, Edward

Locked