CategoryPlot width
CategoryPlot width
Hi,
I would like to know if I could add categories in a CategoryPlot without adujsting the space between categories
I would like to fix a space of 20 pixels and use a scrollbar
Is this possible ?
Thanks
I would like to know if I could add categories in a CategoryPlot without adujsting the space between categories
I would like to fix a space of 20 pixels and use a scrollbar
Is this possible ?
Thanks
Re: CategoryPlot width
Ok so I find the method setCategoryMargin to apply on a CategoryAxis but only the first dataset take account of the margin
Do I need to apply the margin for each dataset?
Do I need to apply the margin for each dataset?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: CategoryPlot width
JFreeChart doesn't work this way. It just draws the chart at the size it is asked to do (this size is determined externally - sometimes by the LayoutManager that controls the size of the ChartPanel containing the chart, sometimes by the caller of the createBufferedImage() or saveChartAsPNG() methods, sometimes by other code).
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: CategoryPlot width
I should add that you could *try* to write some code that adjusts the preferred size of the ChartPanel (if that's what you are using) to take account of the number of categories in the chart.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: CategoryPlot width
You tell that I could try to enlarge the side of my JPanel and the JFreeChart will adjust its width?
Re: CategoryPlot width
This is my CategoryAxis:
This is my ChartPanel:
And this is my JScrollPane:
Here you can see a screenshot of the chart:

Whatever the CategoryMargin is, the space between the dots is the same
Code: Select all
CategoryAxis xAxis = new CategoryAxis("");
xAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI/2.0));
xAxis.setLowerMargin(0.01);
xAxis.setUpperMargin(0.01);
xAxis.setCategoryMargin(0.1);
Code: Select all
cp = new ChartPanel(chart);
cp.addChartMouseListener(this);
cp.setDomainZoomable(false);
cp.setRangeZoomable(false);
cp.setPreferredSize(new Dimension(40*30,1));
Code: Select all
JScrollPane scrollpane = new JScrollPane(panel);
scrollpane.setPreferredSize(new Dimension(1000,1));

Whatever the CategoryMargin is, the space between the dots is the same
Re: CategoryPlot width
I tried to set a preferred size to the chart panel but it's not the solution
I need to fix the length of the domain axis but I don't find a method to do that
I don't even know if it's possible...
In next version coulid it be possible to not auto adjust the size of the plot?
I need to fix the length of the domain axis but I don't find a method to do that
I don't even know if it's possible...
In next version coulid it be possible to not auto adjust the size of the plot?

-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: CategoryPlot width
The "category margin" is NOT an absolute size that defines the size between categories, but is the percentage of the total space that is used for the margin (hence the default value of 0.2 which is 20 %). The "distance between categories" is solely dependent on the lower and upper margin, the available width and the number of categories.
I am not really claer about what you want to achieve, but I think that you want to use a constant distance between categories that is independent of the number of categories. In order to achieve that, the width of the chart will have to grow if more categories are added to the dataset.
A while back, I made a patch that could address this issue (see here). First let me explain what the patch contains:
Additional flag useChartSize in the ChartPanel class. If this is set to false, the ChartPanel will behave as before and draw the chart in the rectangle given by the ChartPanel´s size which in turn might depend on the layout manager.
Additional flags useFixedChartAreaSize and useFixedPlotAreaSize, additional public method getPreferredChartAreaSize() in the JFreeChart class. By the flag useFixedChartAreaSize, it can be indicated that a size should be requested from the chart. If a preferredChartAreaSize is indeed requested by the ChartPanel, the flag useFixedPlotAreaSize comes into play. It indicates which size should be returned. If useFixedPlotAreaSize is false, then a user definable chart size („preferredChartAreaSizeOverride“) is returned. If useFixedPlotAreaSize is true, then the chart asks the Plot for its preferredPlotAreaSize.
If a CategoryPlot or an XYPlot are asked for their preferredPlotAreaSize, they will first retrieve a fixedDataAreaSize. They will then use this size a starting point and add the space for the axes, the axis offsets and the plot insets. This „enlarged size“ is then returned to the JFreeChart. The JFreeChart will then add the space required for the titles and its own inset to this size and return that to the ChartPanel. The ChartPanel then constructs a rectangle from the size and tells the JfreeChart to draw itself inside this rectangle. As a result, you get a chart that has a data area which was defined by the user and which will remain constant even if axes and/or titles are added.
How this might help you? The method that returns the fixedDataAreaSize is defined in the Plot class and simply returns a size that was explicitly set by the user. You could overwrite this method in the CategoryPlot class and return a width that is dynamically calculated based on the available categories of the dataset (good luck with multiple datasets
), and the margins of the CategoryAxis (upper, lower, and between categories).
I am not really claer about what you want to achieve, but I think that you want to use a constant distance between categories that is independent of the number of categories. In order to achieve that, the width of the chart will have to grow if more categories are added to the dataset.
A while back, I made a patch that could address this issue (see here). First let me explain what the patch contains:
Additional flag useChartSize in the ChartPanel class. If this is set to false, the ChartPanel will behave as before and draw the chart in the rectangle given by the ChartPanel´s size which in turn might depend on the layout manager.
Additional flags useFixedChartAreaSize and useFixedPlotAreaSize, additional public method getPreferredChartAreaSize() in the JFreeChart class. By the flag useFixedChartAreaSize, it can be indicated that a size should be requested from the chart. If a preferredChartAreaSize is indeed requested by the ChartPanel, the flag useFixedPlotAreaSize comes into play. It indicates which size should be returned. If useFixedPlotAreaSize is false, then a user definable chart size („preferredChartAreaSizeOverride“) is returned. If useFixedPlotAreaSize is true, then the chart asks the Plot for its preferredPlotAreaSize.
If a CategoryPlot or an XYPlot are asked for their preferredPlotAreaSize, they will first retrieve a fixedDataAreaSize. They will then use this size a starting point and add the space for the axes, the axis offsets and the plot insets. This „enlarged size“ is then returned to the JFreeChart. The JFreeChart will then add the space required for the titles and its own inset to this size and return that to the ChartPanel. The ChartPanel then constructs a rectangle from the size and tells the JfreeChart to draw itself inside this rectangle. As a result, you get a chart that has a data area which was defined by the user and which will remain constant even if axes and/or titles are added.
How this might help you? The method that returns the fixedDataAreaSize is defined in the Plot class and simply returns a size that was explicitly set by the user. You could overwrite this method in the CategoryPlot class and return a width that is dynamically calculated based on the available categories of the dataset (good luck with multiple datasets

Re: CategoryPlot width
You're right: I want a fixed width between categories and a scrollbar if there are more categories
Thanks for your patch
I'll try to use it
Thanks for your patch

I'll try to use it
Re: CategoryPlot width
it's not that easy ^^;
Re: CategoryPlot width
could someone tell me where the plot size in adjusting?
in the CategoryPlot class? in the JFreeChart class ?
I don't know where tweak the JFreeChart librairy in order to fix a size in pixel between category and adjust the width according to the category number
I hope that in the 1.0.14 version it will be possible to choose to adjust or not. Please
in the CategoryPlot class? in the JFreeChart class ?
I don't know where tweak the JFreeChart librairy in order to fix a size in pixel between category and adjust the width according to the category number
I hope that in the 1.0.14 version it will be possible to choose to adjust or not. Please

-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: CategoryPlot width
I have uploaded a new patch that also includes the changed sources for the JFreeChart, Plot, XYPlot and CategoryPlot classes. You just need to replace the old files with the patched ones (keep a backup, of course).
For some reason, there was no calculatePreferredPlotAreaSize-method in the CategoryPlot class
.
But now it is there plus additional parameters fixedCategoryWidth and useFixedCategoryWidth. These can be used to make sure that the width of a category is constant, and that the data area grows if more categories are added (i.e. getFixedDataAreaSize in the Plot class has been overwritten).
The zip also includes two demos: an older one for XYPlots and a newer one for CategoryPlots that uses the new parameters mentioned above and creates a bar which is getting wider as more categories are added. The calculations are quite simple. You might want to look at them and adjust them to your needs, e. g. by taking the margins of the domain axis into account.
For some reason, there was no calculatePreferredPlotAreaSize-method in the CategoryPlot class

But now it is there plus additional parameters fixedCategoryWidth and useFixedCategoryWidth. These can be used to make sure that the width of a category is constant, and that the data area grows if more categories are added (i.e. getFixedDataAreaSize in the Plot class has been overwritten).
The zip also includes two demos: an older one for XYPlots and a newer one for CategoryPlots that uses the new parameters mentioned above and creates a bar which is getting wider as more categories are added. The calculations are quite simple. You might want to look at them and adjust them to your needs, e. g. by taking the margins of the domain axis into account.
Re: CategoryPlot width
thnaks again for your help
I just try your demo and I think now I will be able to do what I want
thanks thanks thanks
the patch link is here
I just try your demo and I think now I will be able to do what I want
thanks thanks thanks
the patch link is here