How to resize the CategoryPlot or plotArea

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tsunpo
Posts: 4
Joined: Thu Feb 01, 2007 9:56 am

How to resize the CategoryPlot or plotArea

Post by tsunpo » Thu Feb 01, 2007 10:22 am

Hi all,

I am using CategoryPlot in my application.

The thing is I can use "categoryaxis.setCategoryMargin(450);"
to avoid the label get overlapped (warpped) since there are too many data I have to show.

But the plotArea seems to be still fixed-sized, actually the whole CategoryPlot except the label is still the same.
I have tried many ways but just can't go on, can anyone help on this issue?

Code: Select all

CategoryAxis categoryaxis = new CategoryAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
categoryaxis.setMaximumCategoryLabelWidthRatio(5F);
categoryaxis.setCategoryMargin(450);
        
LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
lineandshaperenderer.setBaseLinesVisible(false);
lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
NumberAxis numberaxis = new NumberAxis("Value");

CategoryPlot categoryplot = new CategoryPlot(categoryDataset, categoryaxis, numberaxis, lineandshaperenderer);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setOrientation(PlotOrientation.HORIZONTAL);

JFreeChart jfreechart = new JFreeChart("", new Font("SansSerif", 1, 12), categoryplot, true);
Cheers,
George

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 Feb 01, 2007 10:40 am

JFreeChart always tries to draw charts in the space allocated to it, as best it can. It won't try to compute some "optimum size" and resize the chart accordingly. The most troublesome case is where a chart has a lot of categories...here you can get overlapping. The only workarounds are to (a) make your own estimate for the required chart width and resize the chart accordingly, (b) rotate the category labels and/or reduce the font size to fit more in, or (c) recategorise your data so that there are less categories.
David Gilbert
JFreeChart Project Leader

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

tsunpo
Posts: 4
Joined: Thu Feb 01, 2007 9:56 am

Post by tsunpo » Fri Feb 02, 2007 10:20 am

Thank you very much indeed Dave,

After reading through the manual and this forum, I still cannot find any solution related to "resize the chart" for your option (a)

Here is what I did so far:
I use a JSlider to pass values to the "categoryaxis.setCategoryMargin()" in order to spread the labels since we don't want the category get overlapped

However... the plotArea didn't get extended at the same time, it's still in the same size... so the category labels and the diagram which are outside the plotArea will not be displayed.

I tried to do it in the "chartpanel.setPreferredSize(new Dimension(690, 1000));" but it affected the whole picture so the resolution get twisted...

Please help how to resize the chart/CategoryPlot/plotArea to be the same size as the CategoryAxis.

Cheers,
George

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 » Fri Feb 02, 2007 5:07 pm

tsunpo wrote:I tried to do it in the "chartpanel.setPreferredSize(new Dimension(690, 1000));" but it affected the whole picture so the resolution get twisted...
This scaling is done by the ChartPanel when the image gets bigger than a certain size. You can prevent this scaling from happening by increasing the values with setMaximumDrawingWidth() and setMaximumDrawingHeight() in the ChartPanel class.
David Gilbert
JFreeChart Project Leader

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

tsunpo
Posts: 4
Joined: Thu Feb 01, 2007 9:56 am

Post by tsunpo » Mon Feb 05, 2007 9:42 am

Cheers mate, it works!!!!

:)

Locked