how to increase the size of chartpanel Dynamically

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sudhakar
Posts: 6
Joined: Thu Jun 08, 2006 11:35 am

how to increase the size of chartpanel Dynamically

Post by sudhakar » Thu Jun 08, 2006 11:51 am

hai,
i have a problem using jfreecharts. i have attached the chartpanel to a Jscrollpane.Based on real time values the chartpanel should resize.i.e for big chart the size of the chartpanel should be big and i will use scroll bars to view the data and for small graphs the chart panel should be small so that i don not use scroll bars . how can i achive this ?
Thanks.

cringe
Posts: 54
Joined: Wed May 10, 2006 10:39 am
Location: Germany
Contact:

Post by cringe » Thu Jun 08, 2006 12:06 pm

You could get the maximum values for X, Y axis and set the size based on an algorithm that calculates the resulting size for your needs. I don't think that there is an automatic way to set a default resolution/size for a ChartPanel.

sudhakar
Posts: 6
Joined: Thu Jun 08, 2006 11:35 am

whether jfreechart objects can be displayed in jscrollpane

Post by sudhakar » Fri Jun 09, 2006 5:56 am

hai ,
Thanks for your reply. It was mentioned that JfreeChart can be displayed in GUI using ChartPanel only.Is it possible to display in Gui using JScrollPane.
Thanks.

sudhakar
Posts: 6
Joined: Thu Jun 08, 2006 11:35 am

whether jfreechart objects can be displayed in jscrollpane

Post by sudhakar » Fri Jun 09, 2006 5:57 am

hai ,
Thanks for your reply. It was mentioned that JfreeChart can be displayed in GUI using ChartPanel only.Is it possible to display in Gui using JScrollPane.
Thanks.

cringe
Posts: 54
Joined: Wed May 10, 2006 10:39 am
Location: Germany
Contact:

Re: whether jfreechart objects can be displayed in jscrollp

Post by cringe » Fri Jun 09, 2006 6:25 am

sudhakar wrote:It was mentioned that JfreeChart can be displayed in GUI using ChartPanel only.Is it possible to display in Gui using JScrollPane.
Did you try to enclose the ChartPanel in a JScrollPane yet? I don't think that it will give you an error.

sudhakar
Posts: 6
Joined: Thu Jun 08, 2006 11:35 am

Re: whether jfreechart objects can be displayed in jscrollp

Post by sudhakar » Fri Jun 09, 2006 8:26 am

thanks for your reply.
Initially i set the size of the ChartPanel to the size such as width as 1000 and height as 800 and enclosed in a JScrollPane. This worked good for big charts.But for small charts also i have to scroll to view the chart. For my need the ChartPanel should be a scrollpane in which scrollbars appear based on the size of the chart. is there any JFreeChart panel which inherits JScrollPane available in JFreeCharts.
thanks.

Mercer
Posts: 11
Joined: Mon Jun 05, 2006 6:55 pm

Post by Mercer » Mon Jun 12, 2006 6:01 pm

This respons is based on my expereince, others can correct me if I'm off.

The chartPanel is used to decide the physical size to creat the JFreeChart in. If your chartPanel is 200 pixels by 200 pixels, then the JFreeChart will be created (with axises, legends, titles etc) within that size.

If you are making a chartPanel WITHIN a JScrollPane, then no matter the amount of data contained within that JFreeChart, it will expand to fit the chartPanel. This would explain why you ave to scroll no matter how much data is in your JFreeChart.

Possible solution (at least what we did) was to create a JScrollBar independently of JFreeChart (throw it onthe bottom of whatever is holding the chartPanel), and have its 4 values (value, extent, max, min) represent information currently viewed. ie. value = left edge of currently shown graph, extent+value = right edge of currently shown graph, and max and min = the total amount of data available. JFreeChart allows redefininf the upper and lower domain bounds of a plot. Let the user scroll, then redraw the plot based on where the scroll bar ends up.

Not perfect, but it works. And at least this explains the problem you're having.

sudhakar
Posts: 6
Joined: Thu Jun 08, 2006 11:35 am

Post by sudhakar » Tue Jun 13, 2006 3:52 pm

Thanks Mercer.
Thanks for your interest.

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 » Tue Jun 13, 2006 4:36 pm

When I first started work on JFreeChart, I decided that it should draw the charts at whatever size the user requested, rather than try to determine some "optimal" size that depends on how much data there is and who knows what other factors (title length and font, legend position etc), because the latter approach is ultimately very subjective.

So what you are trying to do is going "against the grain" for JFreeChart, but as long as you can code up some algorithm for determining the "optimal" chart width, then embedding the ChartPanel inside a JScrollPane is an approach that can be made to work. The alternative is to restrict the axis range as suggested by Mercer (which may be a better approach if your charts can be very large).
David Gilbert
JFreeChart Project Leader

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

sudhakar
Posts: 6
Joined: Thu Jun 08, 2006 11:35 am

Post by sudhakar » Thu Jun 15, 2006 6:55 am

Thanks for ypur reply David.
You have inherited Jpanel for ChartPanel.It would have been better if you would have inherited JScrollPane for ChartPanel .
Thanks,
R.Sudhakar

cringe
Posts: 54
Joined: Wed May 10, 2006 10:39 am
Location: Germany
Contact:

Post by cringe » Thu Jun 15, 2006 9:17 am

No, it's not. Enclosing components in Scrollpanes is up to the GUI designer, not the library itself. Maybe there should be a method like ChartPanel.setFixedSize(int, int), but I don't think that everybody want scrollbars on their charts...

Only my 2ct.

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 » Thu Jun 15, 2006 10:15 am

sudhakar wrote:You have inherited Jpanel for ChartPanel.It would have been better if you would have inherited JScrollPane for ChartPanel .
That would have been a mistake. Among other things, you need to bear in mind that JFreeChart output can be sent to a number of places, not just the screen. On the screen, scrollbars are a possibility, but they're not available on a printed page, or in a PDF file, or in a PNG image.

I'm aware that there are use cases for charting where people would like the chart to automatically size itself using some kind of "preferred size" mechanism. JFreeChart just doesn't support that case. It approaches the problem from the other direction: here is the space available, now draw a chart in there as best you can.
David Gilbert
JFreeChart Project Leader

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

Locked