views:

31

answers:

1

Hi

I'm drawing a graph using Java 2d graphics (i.e. drawing and filling rectangles) straightaway on a JFrame from a set of values stored in an Arraylist. But when the ArrayList has very large number of values (can even go upto 3500 in size), the drawing is compressed - where the graph seems less informative and even the labels on the X-axis are not displayed. Is there a way I can make the graph displayable in several page-wise manner (i.e. say limiting so that a page can show upto 100 values - the remaining in different pages where the user can navigate page-wise).

How can I approach this type of a situation? Are there any stacked-layouts I can use? Can I use panels? But then can I draw half way in panels (since the graph is drawn inside a loop - until the elements of arraylist are read)? Or can I have a scrollable panel? I have currently drawn everything manually without using drag-and-drop GUI in NetBeans.

Greatly appreciate any insight, suggestions and ideas.

Many thanks in advance

+1  A: 

A quick solution is to just put your panel in a JScrollPane. You could also use a card layout. Just put the graph on n pages and show 1/nth part of the graph on each page. That should be relatively easily since you are drawing the graph yourself. Frankly though, you don't even need a card layout for what you are doing. When the button is pushed just tell your chartpanel what portion of the graph to show and have it update itself accordingly.

Another option is to use a charting library instead of creating your chart manually. JFreeChart is a commonly used library which allows the user to zoom in and out of the chart.

Jay Askren