How do i control the size of the bubbles in a bubble chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
demonhead
Posts: 24
Joined: Thu May 25, 2006 5:44 am

How do i control the size of the bubbles in a bubble chart

Post by demonhead » Wed Jan 24, 2007 2:09 pm

Hi All,
Does anyone have any idea about how to control the size of the largest bubble in a JFree Bubble Chart.

Sample this dataset
--------------------------------
Month Savings Size
0.5 12000 1
3.5 10000 1

The default scale type for a BubbleChart is SCALE_ON_RANGE_AXIS, because of which the bubble chart does not get rendered properly.
Two huge bubbles get rendered, and go beyond the chart boundaries, infact one does not even come to know that there are bubbles on the chart
.

Changing the scale type does not help.

Ideally what should happen is, it should adjust the size of the biggest bubble such that it is seen on the chart.

If you feed the same dataset to Excel, you will know what i mean.

It seems as if it does not take the Z value into consideration at all.

Is there any patch which takes care of this???


Any ideas????

Thanks.

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 » Wed Jan 24, 2007 4:06 pm

The width and height of the bubble is determined by the z-value in your dataset. The z-value is first converted to Java2D units by scaling against the domain or range axis, according to the scaleType attribute that you specify in the constructor. In the SCALE_ON_BOTH_AXES case, the width is the z-value scaled along the domain axis, and the height is the z-value scaled along the range axis (this usually results in an ellipse for the bubble).

The auto-range calculate for the axes does not currently take the bubble size into account, so you might want to increase the lower and upper margins on the axes to allow for this.
David Gilbert
JFreeChart Project Leader

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

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Tue Oct 28, 2008 9:14 am

JFreeChart 1.0.10 and 1.0.11
The equation is quite simple.(XYZDataset, DefaultXYZDataset)

When we instantiate renderer for bubble chart. We declare as follow:
XYItemRenderer xyItemRendererBubble = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_BOTH_AXIS);
XYItemRenderer xyItemRendererBubble = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_DOMAIN_AXIS);
XYItemRenderer xyItemRendererBubble = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
or
XYItemRenderer xyItemRendererBubble = new XYBubbleRenderer(); //default SCALE_ON_BOTH_AXIS

Let's us open the XYBubbleRenderer class at package org.jfree.chart.renderer.xy
Goto method: public void drawItem(Graphics2D g2, ...etc.)
At switch(getScaleType()), u will observe 3 case: SCALE_ON_DOMAIN_AXIS, SCALE_ON_RANGE_AXIS and default
default equal to SCALE_ON_BOTH_AXIS.

In this example, I use SCALE_ON_RANGE_AXIS as sample, cause relative easy to understand.
In ur chart, on range-axis maybe form by 100. And it divide into 9 dotted lines which 1 interval is 10.
Then, when u want to draw a bubble which the Z-value (equal to diameter of bubble=2 radius).
If diameter = 10, then the z-value for the seriesItem should be 10.0 If u dataset range axis is 10000,
then u want a bubble conquer 10% of the chart range, the z-axis(diameter) should be 1000 indeed.

*To automatic calculate to fit the best z-value on various chart type. U will need a double value called dRatio.

dZ * dRatio will equal to the Z-value if in SCALE_ON_RANGE_AXIS type.
How to determine dRatio? U may use ur talented brain to think about it.
(CLUE:based on dataset on different stock)


Pretty easy, ya?

Locked