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
Setting point size
Your must define your own shapes
Code: Select all
renderer.setShape(new Rectangle(2, 2));
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!
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!
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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.hotwingz wrote:However, when you zoom out, the range that is displayed is its own range and not the common range.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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.angel wrote:Your must define your own shapesCode: Select all
renderer.setShape(new Rectangle(2, 2));

Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
A method that works
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 .
:
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

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
Re: A method that works
I left a small typo in the code below: The fifth line of code should read:
for (int i = 0; i < numSeries; i++) { .
Joel
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 .:
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