Multiple chart alignment
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Multiple chart alignment
Hi,
I've have some trouble getting my charts aligned.
Here's a screen:
I would like charts in the bottom to be aligned with the chart in the top, between the 2 line in yellow. (Domain axis are the sames values ie 0->1439 minutes)
A solution may be to put a left and right Insets (corresponding to the yellow line) in the bottom charts but i don't know how to calculate them ?
Thanks in advance,
I've have some trouble getting my charts aligned.
Here's a screen:
I would like charts in the bottom to be aligned with the chart in the top, between the 2 line in yellow. (Domain axis are the sames values ie 0->1439 minutes)
A solution may be to put a left and right Insets (corresponding to the yellow line) in the bottom charts but i don't know how to calculate them ?
Thanks in advance,
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Multiple chart alignment
Have a look at the CombinedDomainXYPlot class.
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Re: Multiple chart alignment
I've already at the CombinedDomainXYPlot last month but there was something wrong with XYStepAreaRenderer. I don't remember what -_-
I'll give it a try.
Thank you/Merci Para.
I'll give it a try.
Thank you/Merci Para.
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Re: Multiple chart alignment
Ok, i've tried CombinedDomainXYPlot and it's ok but it doesn''t fit my "special" needs.
The "subcharts" in the bottom are rendered in a JTable cell, so i can control the chart's height (I know CombinedXYPLot have weight).
So, there is no way to calculate Insets or Lower/UpperMargin ?
In the screenshot above, alignments are almost ok by setting an arbitrary LowerMargin on subcharts. But when i resize the window, LowerMargins are not OK.
The "subcharts" in the bottom are rendered in a JTable cell, so i can control the chart's height (I know CombinedXYPLot have weight).
So, there is no way to calculate Insets or Lower/UpperMargin ?
In the screenshot above, alignments are almost ok by setting an arbitrary LowerMargin on subcharts. But when i resize the window, LowerMargins are not OK.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Multiple chart alignment
I do not fully understand these statements.CoreDumped wrote:Ok, i've tried CombinedDomainXYPlot and it's ok but it doesn''t fit my "special" needs.
The "subcharts" in the bottom are rendered in a JTable cell, so i can control the chart's height (I know CombinedXYPLot have weight).
What "special needs" do you have?
And have you placed the two chartsin separate cells of a JTable or just the bottom one (the horizontal bar chart)?
If the horizontal bar chart is a JFreeChart as well, I would go for a CombinedPlot. The bottom chart can be realized as an XYPlot as the upper one.
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Re: Multiple chart alignment
Horizontal plots are ChartPanel you're right, all in seperate cells of a JTable.
The top chart is in a JPanel (BorderLayout) with the JCalendar and the "other" stuffs
My "needs" : JCalendar must be to the top left, "A LABEL" must be align with his plot (left aligned like the screenshot, and also vertical aligned with the JCalendar).
TimeAxis must be visible under the 1rst chart unlike the CombinedDomainPlot witch draw domainAxis on the bottom.
[edit]:
What i have done with CombinedDomain :
I need to place A JTable and a JPanel (with a JCalendar) in the chart area (red square) if i go with the combined way.
Sorry for my bad english and thank you for your interest.
The top chart is in a JPanel (BorderLayout) with the JCalendar and the "other" stuffs
My "needs" : JCalendar must be to the top left, "A LABEL" must be align with his plot (left aligned like the screenshot, and also vertical aligned with the JCalendar).
TimeAxis must be visible under the 1rst chart unlike the CombinedDomainPlot witch draw domainAxis on the bottom.
[edit]:
What i have done with CombinedDomain :
I need to place A JTable and a JPanel (with a JCalendar) in the chart area (red square) if i go with the combined way.
Sorry for my bad english and thank you for your interest.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Multiple chart alignment
Frankyl, I am still a bit confused because every new image is slightly different from the previous ones. So maybe the following advice isn´t all that helpful:
If you want to left align charts that are in different ChartPanels, first you have to left align the ChartPanels! JFreeChart wont be really helpful with this task, since it is primarily a Swing layout issue. But let us assume that you have managed to solve that.
Then, you need to left align the plot areas of the two different chart. Here, the main issue is probably the length of the tick marks of the range axes of both plots. If you can guarantee that the tick labels of the range axes are of identical length, then the plot areas should be automatically left aligned as well (unless the labels of the two axes are visible and have a different font size, but this should be easily noticeable). If you need to show the tick labels, then it can be difficult to make them having the same length. However, if you call
on both XYPlots, then the plot will reserve the mentioned space (in pixels) for drawing the axes, even though the actual size requirement might be smaller.
If you want to left align charts that are in different ChartPanels, first you have to left align the ChartPanels! JFreeChart wont be really helpful with this task, since it is primarily a Swing layout issue. But let us assume that you have managed to solve that.
Then, you need to left align the plot areas of the two different chart. Here, the main issue is probably the length of the tick marks of the range axes of both plots. If you can guarantee that the tick labels of the range axes are of identical length, then the plot areas should be automatically left aligned as well (unless the labels of the two axes are visible and have a different font size, but this should be easily noticeable). If you need to show the tick labels, then it can be difficult to make them having the same length. However, if you call
Code: Select all
AxisSpace rangeSpace = new AxisSpace();
rangeSpace.ensureAtLeast(50, RectangleEdge.LEFT);
plot.setFixedRangeAxisSpace(rangeSpace);
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Re: Multiple chart alignment
Thank you Paradox.
Yes, issue is ticks marks&labels of top charts! RangeAxis is set visible(false) for barcharts.
So I've tried AxisSpace, and we are close to find the solution.
Here : left space of 50pixels as you mentionned above in all 7 charts(1 per jtable row and top chart), top and bottom still not perfectly aligned:
Here: 50 pixels left space on top chart, and i put97 left pixels in bottom charts. It's ok, it's what i want (you can see DomainCrosshair on '00:00')
On the bottom charts i've also put an right space of 47pixels.
Another information, maybe not useful : Lower/Upper margin of DomainAxis are both set to 0.02 for the top chart and set to 0.001 for bottom charts.
How i can calculate these 47 pixels ?
Thank you in advance
Yes, issue is ticks marks&labels of top charts! RangeAxis is set visible(false) for barcharts.
So I've tried AxisSpace, and we are close to find the solution.
Here : left space of 50pixels as you mentionned above in all 7 charts(1 per jtable row and top chart), top and bottom still not perfectly aligned:
Here: 50 pixels left space on top chart, and i put97 left pixels in bottom charts. It's ok, it's what i want (you can see DomainCrosshair on '00:00')
On the bottom charts i've also put an right space of 47pixels.
Another information, maybe not useful : Lower/Upper margin of DomainAxis are both set to 0.02 for the top chart and set to 0.001 for bottom charts.
How i can calculate these 47 pixels ?
Thank you in advance
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Multiple chart alignment
Do you mean the gap between the left border of the data area and the first tick mark?
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Re: Multiple chart alignment
Hi Paradoxoff,
Yes.
Yes.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Multiple chart alignment
AFAICS, there is no easy way to acess the value of the first tick label from outside of the rendering process. During the rendering a List of Ticks is created, but this is not exposed to the outside.
It seems that the first value in the dataset has the same time coordinate than the tick mark. If you know this value (lets call that "xFirst"), and if you can access the data area and the XYPlot of the upper chart, then the gap in pixels is
domainAxis.java2DToValue(xFirst,dataArea, xyplot.getDomainAxisEdge()) - dataArea.getX().
It seems that the first value in the dataset has the same time coordinate than the tick mark. If you know this value (lets call that "xFirst"), and if you can access the data area and the XYPlot of the upper chart, then the gap in pixels is
domainAxis.java2DToValue(xFirst,dataArea, xyplot.getDomainAxisEdge()) - dataArea.getX().
-
- Posts: 8
- Joined: Wed Aug 31, 2016 10:30 am
- antibot: No, of course not.
Re: Multiple chart alignment
Thx Para. I'll try asap.