Sizing JFreeChart

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

Sizing JFreeChart

Post by Chris » Wed Dec 13, 2000 4:48 am

Hello,

I'm a biochemistry student, and my programming skills are a little lacking. I'm trying to use JFreeChart to plot some data, but the number of points on the xy graph exceeds a few hundred thousand, and it's pretty illegible. So I tried to put everything in a JScrollPane, but I can't seem to get the chart to stretch out without taking its JInternalFrame with it. It seems to straightforward with other swing components, but I can't seem to keep my JInternalFrame small while making the JFreeChart large. Here's the code segment where I build my chart. Any insight would be much appreciated. Thanks.

public class PLIChart extends JInternalFrame
{
XYDataSource data;
JScrollPane content;
public PLIChart(XYDataSource d)
{
super("PLI Analysis", true, true, true, true);
setSize(500, 400);
this.setResizable(true);
data = d;
JFreeChart chart = JFreeChart.createXYChart(data);
Plot xyPlot = chart.getPlot();
NumberAxis hhAxis = (NumberAxis) xyPlot.getAxis(Plot.HORIZONTAL_AXIS);
hhAxis.setAutoTickValue(true);
JFreeChartPanel pli = new JFreeChartPanel(chart);
content = new JScrollPane(pli);
getContentPane().setSize(1000, 400);
getContentPane().add(content, BorderLayout.CENTER);
}

David Gilbert

RE: Sizing JFreeChart

Post by David Gilbert » Wed Dec 13, 2000 1:27 pm

Hi Chris,

The JFreeChartPanel will be resized by the layout manager of whatever container it has been added to. JScrollPane probably looks at the preferred size...I haven't got the code in front of me, did I implement getPreferredSize()? If I didn't, then you should probably add it. If there are any other things that should be included in JFreeChartPanel to make it behave properly, please send me a patch.

I think once you get it working, you will run into a performance problem. JFreeChart draws all the points in the datasource, whether they are visible on screen or not. Each time you scroll in the JScrollPane, JFreeChart will redraw all the data points which will be slow.

I want to make some improvements so that the plot classes can request only the data they require, so that if you restrict the range on the x-axis (say), then the charts will redraw quicker. I'm thinking of implementing a datasource that uses a TreeMap for the x-values.

Let me know if you have any ideas from the work you are doing...

Regards,

DG.

Fabien D.

RE: Sizing JFreeChart

Post by Fabien D. » Wed Dec 13, 2000 2:09 pm

Hi,
couldn't we use an appropriate SetClipBox() to draw only needed parts of the graph ?

David Gilbert

RE: Sizing JFreeChart

Post by David Gilbert » Thu Dec 14, 2000 1:33 pm

Hi Fabien,

There's no problem with the display - not that I'm aware of anyway. It's just that the plot classes step through all the data in the data source, even if the current range on the axis requires only 10% (say) of the data. So I'd like to make that more efficient, so that large data sets work as well as possible...

DG.

MNusinov
Posts: 15
Joined: Tue Jul 03, 2007 7:41 pm

Post by MNusinov » Tue Jul 03, 2007 7:42 pm

I know this thread is pretty old but I had come across a similar problem and was wondering if a solution was resolved since this thread initially was created.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jul 04, 2007 10:07 am

In JFreeChart 1.0.6, the XYPlot class will plot only a subset of data values *if* the dataset is ordered by x-value (see the getDomainOrder() method in the XYDataset interface).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

MNusinov
Posts: 15
Joined: Tue Jul 03, 2007 7:41 pm

Post by MNusinov » Fri Jul 06, 2007 2:19 pm

Actually I was looking for more of a solution with the sizing of the chart in a ScrollPane. I have a gantt chart that I would like to scroll along the Y axis and thought if a solution for scrolling this chart was found it would be applicable to my problem as well.

Locked