Creating a wide (scrollable) graph

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

Creating a wide (scrollable) graph

Post by Graham Perks » Fri Jan 17, 2003 9:49 pm

I'm evaluating JFreeChart and so far things are looking great! I have only two problems - here is the first:

I have a graph with several hundred or potentially thousands of vertical bars. I want the user to be able to scroll sideways. I've put a JScrollPane around the chart but no scrollbars appear - the graph just scales itself to fit the available space. How do I tell the graph a minimum width to use?

I tried the zoom functions but that didn't work for some reason. I just selected Zoom->Horizontal axis but it made no difference.

What am I missing?

Thanks,
Graham.

David Gilbert

Re: Creating a wide (scrollable) graph

Post by David Gilbert » Sat Jan 18, 2003 9:05 am

Hi Graham,

When you put a ChartPanel into a JScrollPane, I think you need to set the preferred size of the ChartPanel to some dimension, otherwise it just resizes to the view area in the scrollpane. The chart is always drawn at whatever size the ChartPanel is given by the layout manager responsible for the panel.

One other thing to look out for. The ChartPanel has maximumDrawHeight and maximumDrawWidth attributes...if the panel is taller or wider than these values, the chart is drawn at the size specified by the attributes, then scaled up to fill the available space. You probably want to increase the maximumDrawWidth from the default value.

Regards,

Dave Gilbert

David Gilbert

Re: Creating a wide (scrollable) graph

Post by David Gilbert » Sat Jan 18, 2003 9:08 am

The zoom function doesn't work for category axes. I need to modify the popup menu code so that it only presents the valid zooming options.

Regards,

DG

Graham Perks

Re: Creating a wide (scrollable) graph

Post by Graham Perks » Mon Jan 20, 2003 10:23 pm

Thanks! I played around with the scroll pane some more and it now shows the scroll bars. Thanks for the hint about setting the ChartPanel size!

This sort of thing works:

// Set size graph should be drawn at.
chartPanel.setPreferredSize( new Dimension( 600, 100 ) );

// Wrap in scroll pane
scrollingGraphPanel = new JScrollPane( chartPanel );

// Set size scroll pane should come up at, showing scrollbars for the larger graph.
scrollingGraphPanel.setPreferredSize( new Dimension( 300, 120 ) );

Cheers!

Artemis

Re: Creating a wide (scrollable) graph

Post by Artemis » Tue Jan 21, 2003 6:45 am

Hi,

I want to know in which class should I place the above code ?

Thanks

Artemis

Locked