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.
Creating a wide (scrollable) graph
Re: Creating a wide (scrollable) graph
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
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
Re: Creating a wide (scrollable) graph
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
Regards,
DG
Re: Creating a wide (scrollable) graph
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!
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!
Re: Creating a wide (scrollable) graph
Hi,
I want to know in which class should I place the above code ?
Thanks
Artemis
I want to know in which class should I place the above code ?
Thanks
Artemis