Extra-Axis in the same plane?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Didi-chan
Posts: 5
Joined: Fri Feb 27, 2009 1:53 pm

Extra-Axis in the same plane?

Post by Didi-chan » Fri Feb 27, 2009 2:08 pm

First of all, I want to apologize for my English, I am from Spain so this is difficult to me.

Ok, I have the next problem. I have made a graph with an extra-axis. The problem is that the bars from the extra axis are hidden because, the bars of the principal axis are showed first. You can only see the bars from the extra axis if their values in Y axis are bigger than the principal axis ones. How could I solve this? Is there some way to put the bars one next to the other instead of behind?

Thank you.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Extra-Axis in the same plane?

Post by paradoxoff » Fri Feb 27, 2009 3:56 pm

I assume that your plot is a CategoryPlot, that your "extra axis" is a ValueAxis, that you have at least two CategoryDatasets, and that both are mapped to the same domain axis but different range axes.
1. You can call plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD) (the default is for some reason DatasetRenderingOrder.REVERSE). Then, the first dataset will be rendered first and the second dataset will be renderer on top of that. However, then the bars from the principal axis might be hidden by the second set of bars, which is probably something that you do not want as well!
2. You can grab the renderer for the first dataset (I assume that this renderer is a BarRenderer) and call renderer.setBarWidth(0.8). That will make the bars of the first dataset (which are presently rendered last, i.e. on top of the others) more narrow. If the bars of the second dataset (which is currently rendered first, i.e. in the background) have their original width (1.0, i.e. 100 %), then they will be wider than the bars in the foreground and will be visible even if the values (i.e. the bar height) is lower.

Didi-chan
Posts: 5
Joined: Fri Feb 27, 2009 1:53 pm

Re: Extra-Axis in the same plane?

Post by Didi-chan » Mon Mar 02, 2009 8:58 am

Thank you very very much for answer me, but I think that won't do.

The first solution because, I need both bars to be showed. The second solution either because I need to see the entire bars, not just a portion. And something else, what I need to do is some kind of dinamic graphic. I mean, I can't assume there will be two datasets, maybe it will be 2 or maybe 5, as many as the user wants.

Any other solution? I'm desperate :(

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Extra-Axis in the same plane?

Post by paradoxoff » Mon Mar 02, 2009 8:02 pm

Didi-chan wrote: The first solution because, I need both bars to be showed. The second solution either because I need to see the entire bars, not just a portion. And something else, what I need to do is some kind of dinamic graphic. I mean, I can't assume there will be two datasets, maybe it will be 2 or maybe 5, as many as the user wants.

Any other solution?
Probably there is no simple solution for this problem.
If you need to see the full area of all bars, i.e. if any kind of bar overlap has to be avoided, you will have to develop a more complicated mechanism to track the data across datasets:
- Count the rows of all datasets (that requires that the datasets take the data from the same columns. But if that is not fulfilled, then there is probably no way at all to show the data in a comprehensive way).
- Add the rows from e. g. the second dataset onwards to the first with null values.
- Insert the rows from the first dataset in the second dataset, ahead of the original rows from the second dataset. Add the data from the third dataset to the second dataset.
- And so forth.
The goal is to give all datasets the same number of rows and to fill the rows that are not part of original dataset with null values.
If you then use normal BarRenderers to show the data, all bars should be visible. Let us assume that dataset A contained two rows and dataset B contained three. After the addition/insertion described above, both datasets will contain five rows. Only the first two of dataset A will contain real data, but space will be reserved for all rows, hence the bars will be placed on the left of the space reserved for the bars. Only the last three rows of dataset B will contain real data, but again, space will be reserved for the first two rows as well, and the bars for the last three series will be drawn exclusively on the right.
I do not know whether a DefaultCategoryDataset provides the capability for this addition/insertion mechanism. Probably not. In that case you will have to develop your own CategoryDataset implementation or implement another way to distribute the data across several datasets in an appropriate way.

Didi-chan
Posts: 5
Joined: Fri Feb 27, 2009 1:53 pm

Re: Extra-Axis in the same plane?

Post by Didi-chan » Tue Mar 03, 2009 8:51 am

Thank you. Actually, i had already heard about that system of null values series. But i wanted to avoid it because, I am not talking about two datasets, as I said before, it could be a lot of them. But I have read a lot about this and it seems that I have not a better option. I asked here because I thought that maybe there was some method which could do this. I'll try that way. Thank you very much, I see you took a lot of trouble to answer and explain me everything. Sweet :D .

Locked