Setting point size

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Guest

Setting point size

Post by Guest » Mon Apr 18, 2005 4:13 pm

Hello All,
I'm displaying scatter graphs with a lot of points. Since they tend to cluster, I end up with blobs of points. Is there a way to alter the default size of each point?
I've checked XYItemRenderer and XYLineAndShapeRenderer, but they don't offer a way to set the size.

Any help would be appreciated.

Thanks

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Mon Apr 18, 2005 4:52 pm

Your must define your own shapes

Code: Select all

renderer.setShape(new Rectangle(2, 2));

hotwingz
Posts: 10
Joined: Fri Apr 01, 2005 11:06 pm

Post by hotwingz » Mon Apr 18, 2005 5:38 pm

Thanks, that works like a charm. However, it results in some oddball behaviour.

I've set these group of plots to have a common range. That is, I've gotten the maximum and minimum for this group of plots and am using it as the maximum and minimum for each plot.

Now, when the graphs are first displayed, they all share a common range, even the graph with changed points. The changed graph also behaves as expected when zooming in. However, when you zoom out, the range that is displayed is its own range and not the common range.

Maybe I should change all the graphs and then see what happens.

Anyway, thanks again!

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 Apr 18, 2005 5:43 pm

hotwingz wrote:However, when you zoom out, the range that is displayed is its own range and not the common range.
Zooming out will restore the auto-calculated range, which fits the axes to the data in the dataset. That isn't always what the user wants, so an enhancement is required here to allow the 'non-zoomed' ranges to be specified.
David Gilbert
JFreeChart Project Leader

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

mhilpert
Posts: 497
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

Post by mhilpert » Tue Jun 07, 2005 1:53 pm

angel wrote:Your must define your own shapes

Code: Select all

renderer.setShape(new Rectangle(2, 2));
But then I loose the automatic switch between series (one with circles, one with rectangles, etc.). I miss a setSize() method in the renderers that support shapes. :roll:
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Tue Jun 07, 2005 3:53 pm

Automatic switch? I think there are just default colors and shapes for the series.

Joel

A method that works

Post by Joel » Tue Aug 02, 2005 2:29 am

I know this is late, but I just faced the same issue today. Here is a snippet of code that worked for me (symbol types and colors are preserved, just the size is rescaled by .8):

XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
float scaleFactor = .8F; // use to rescale the datapoints smaller
for (int i = 1; i <= numSeries; i++) {
Shape shape = renderer.getSeriesShape(i);
System.out.println(shape.getClass().getName());
if (shape.getClass() == Rectangle2D.Double.class) {
Rectangle2D.Double rect = (Rectangle2D.Double)shape;
rect.height = rect.height * scaleFactor;
rect.width = rect.width * scaleFactor;
rect.x = rect.x * scaleFactor;
rect.y = rect.y * scaleFactor;
} else if (shape.getClass() == Ellipse2D.Double.class) {
Ellipse2D.Double ellipse = (Ellipse2D.Double)shape;
ellipse.height = ellipse.height * scaleFactor;
ellipse.width = ellipse.width * scaleFactor;
ellipse.x = ellipse.x * scaleFactor;
ellipse.y = ellipse.y * scaleFactor;
} else if (shape.getClass() == Polygon.class) {
Polygon poly = (Polygon)shape;
int[] xp = poly.xpoints;
int[] yp = poly.ypoints;
for (int j = 0; j < poly.npoints; j++) {
poly.xpoints[j] = Math.round((float)poly.xpoints[j] * scaleFactor);
poly.ypoints[j] = Math.round((float)poly.ypoints[j] * scaleFactor);
}
}
}
renderer.setDefaultShapesVisible(true);
renderer.setDefaultShapesFilled(false);
}

The one catch in the above code is that Polygons are specified with int[], so only certain discreet values are allowed. The default values are: x = [0 3 -3] and y = [-3 3 3].

To test that only the java.awt.geom.Rectangle2D$Double,
java.awt.geom.Ellipse2D$Double, and
java.awt.Polygon classes are used to form the various symbols, I made a plot with 10 serieses. No other classes were used. Best
Joel

Joel

Re: A method that works

Post by Joel » Tue Aug 02, 2005 4:17 am

I left a small typo in the code below: The fifth line of code should read:
for (int i = 0; i < numSeries; i++) { .
Joel
Joel wrote:I know this is late, but I just faced the same issue today. Here is a snippet of code that worked for me (symbol types and colors are preserved, just the size is rescaled by .8):

XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
float scaleFactor = .8F; // use to rescale the datapoints smaller
for (int i = 1; i <= numSeries; i++) {
Shape shape = renderer.getSeriesShape(i);
System.out.println(shape.getClass().getName());
if (shape.getClass() == Rectangle2D.Double.class) {
Rectangle2D.Double rect = (Rectangle2D.Double)shape;
rect.height = rect.height * scaleFactor;
rect.width = rect.width * scaleFactor;
rect.x = rect.x * scaleFactor;
rect.y = rect.y * scaleFactor;
} else if (shape.getClass() == Ellipse2D.Double.class) {
Ellipse2D.Double ellipse = (Ellipse2D.Double)shape;
ellipse.height = ellipse.height * scaleFactor;
ellipse.width = ellipse.width * scaleFactor;
ellipse.x = ellipse.x * scaleFactor;
ellipse.y = ellipse.y * scaleFactor;
} else if (shape.getClass() == Polygon.class) {
Polygon poly = (Polygon)shape;
int[] xp = poly.xpoints;
int[] yp = poly.ypoints;
for (int j = 0; j < poly.npoints; j++) {
poly.xpoints[j] = Math.round((float)poly.xpoints[j] * scaleFactor);
poly.ypoints[j] = Math.round((float)poly.ypoints[j] * scaleFactor);
}
}
}
renderer.setDefaultShapesVisible(true);
renderer.setDefaultShapesFilled(false);
}

The one catch in the above code is that Polygons are specified with int[], so only certain discreet values are allowed. The default values are: x = [0 3 -3] and y = [-3 3 3].

To test that only the java.awt.geom.Rectangle2D$Double,
java.awt.geom.Ellipse2D$Double, and
java.awt.Polygon classes are used to form the various symbols, I made a plot with 10 serieses. No other classes were used. Best
Joel

Locked