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);
}
Sizing JFreeChart
RE: Sizing JFreeChart
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.
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.
RE: Sizing JFreeChart
Hi,
couldn't we use an appropriate SetClipBox() to draw only needed parts of the graph ?
couldn't we use an appropriate SetClipBox() to draw only needed parts of the graph ?
RE: Sizing JFreeChart
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.
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.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

