Change subplot weight?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jiangshachina
Posts: 32
Joined: Fri May 26, 2006 12:56 pm
Location: Beijing, China

Change subplot weight?

Post by jiangshachina » Fri Aug 08, 2008 10:19 am

I made a CombinedDomainXYPlot, and used method

Code: Select all

combinedDomainXYPlot.add(plot1, 2)
combinedDomainXYPlot.add(plot2, 1)
to add two sub-XYPlots. The image is shown as the followings,
Image

If I had added the two sub-XYPlots, and then changed their weight, the code like,

Code: Select all

List subplots = combinedDomainXYPlot.getSubplots();
XYPlot plot1 = (XYPlot) subplots.get(0);
XYPlot plot2 = (XYPlot) subplots.get(1);
plot1.setWeight(1);
plot2.setWeight(1);
But the result was...
Image
It seems that something did't know the change.
How to cancel the trouble?

Thanks!
a cup of Java, cheers!
Sha Jiang

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

Post by paradoxoff » Fri Aug 08, 2008 12:26 pm

That seems to be a bug.
I just checked the sources. The CombinedDomainXYPlot contains a variable totalWeight (which is the sum of the weights of the subplots). This variable is updated when subplots are added or removed, but not when the weight of a subplot is changed!
XYPlot.setWeight(int weight) simply sets the weight and calls fireChangeEvent() which should invoke CombinedDomainXYPlot .plotChanged(). The latter method simply forwards the event to PlotChangeListeners registered on the CombinedDomainXYPlot.
Not sure how this can be changed? Either we need a new method in the CombinedXXXPlot-classes for updating the total weight that can be called from its subplots or a better mechanism for distinguishing between different plot change event types.

jiangshachina
Posts: 32
Joined: Fri May 26, 2006 12:56 pm
Location: Beijing, China

Post by jiangshachina » Mon Aug 11, 2008 9:06 am

Something may not be notified.
a cup of Java, cheers!
Sha Jiang

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 » Mon Aug 11, 2008 1:33 pm

Thanks for spotting and reporting this. I think the simplest fix is to do away with the totalWeight field (in all the CombinedXXXPlot classes) and calculate the value on-the-fly when it is needed. I just committed a patch to Subversion to do just that (to be included in the 1.0.11 release).
David Gilbert
JFreeChart Project Leader

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

jiangshachina
Posts: 32
Joined: Fri May 26, 2006 12:56 pm
Location: Beijing, China

Post by jiangshachina » Tue Aug 12, 2008 9:39 am

I have another two questions:
[1]As shown as the above pictures, all of tick label are too close to the bottom of the Volume area.
How to adjust the gap between them?
Note: All of ticks are added by manual(override method DateAxis.refreshTicks).

[2]I wish each "Price" point has the same X-axis value that the center(now it's start) of "Volume" bar has.
What I have to do?

Thanks!
a cup of Java, cheers!
Sha Jiang

jiangshachina
Posts: 32
Joined: Fri May 26, 2006 12:56 pm
Location: Beijing, China

Post by jiangshachina » Mon Aug 18, 2008 10:06 am

jiangshachina wrote:I have another two questions:
[1]As shown as the above pictures, all of tick label are too close to the bottom of the Volume area.
How to adjust the gap between them?
Note: All of ticks are added by manual(override method DateAxis.refreshTicks).
I shall know

Code: Select all

Axis.setTickLabelInsets(RectangleInsets insets)
a cup of Java, cheers!
Sha Jiang

Locked