Multiple chart alignment

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Multiple chart alignment

Post by CoreDumped » Mon Sep 26, 2016 9:59 am

Hi,

I've have some trouble getting my charts aligned.

Here's a screen:
Image

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,

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

Re: Multiple chart alignment

Post by paradoxoff » Mon Sep 26, 2016 6:22 pm

Have a look at the CombinedDomainXYPlot class.

CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Re: Multiple chart alignment

Post by CoreDumped » Tue Sep 27, 2016 12:47 pm

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.

CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Re: Multiple chart alignment

Post by CoreDumped » Thu Sep 29, 2016 8:30 am

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.

Image

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

Re: Multiple chart alignment

Post by paradoxoff » Thu Sep 29, 2016 12:52 pm

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).
I do not fully understand these statements.
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.

CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Re: Multiple chart alignment

Post by CoreDumped » Thu Sep 29, 2016 1:58 pm

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 :
Image
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.

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

Re: Multiple chart alignment

Post by paradoxoff » Thu Sep 29, 2016 5:56 pm

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

Code: Select all

    AxisSpace rangeSpace = new AxisSpace();
    rangeSpace.ensureAtLeast(50, RectangleEdge.LEFT);
    plot.setFixedRangeAxisSpace(rangeSpace);
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.

CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Re: Multiple chart alignment

Post by CoreDumped » Fri Sep 30, 2016 8:55 am

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:
Image

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')
Image

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

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

Re: Multiple chart alignment

Post by paradoxoff » Wed Oct 05, 2016 8:33 pm

Do you mean the gap between the left border of the data area and the first tick mark?

CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Re: Multiple chart alignment

Post by CoreDumped » Thu Oct 06, 2016 7:05 am

Hi Paradoxoff,

Yes.

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

Re: Multiple chart alignment

Post by paradoxoff » Thu Oct 06, 2016 4:34 pm

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().

CoreDumped
Posts: 8
Joined: Wed Aug 31, 2016 10:30 am
antibot: No, of course not.

Re: Multiple chart alignment

Post by CoreDumped » Mon Oct 10, 2016 8:12 am

Thx Para. I'll try asap.

Locked