views:

425

answers:

3

Currently, the PolarChart joins all the coordinates with lines creating a polygon. I just want it to plot each point with a dot and NOT join them together. Is this possible?

I have tried using translateValueThetaRadiusToJava2D() and Graphics2D to draw circles but it's very clunky and contrived.

Any suggestions welcome!

+1  A: 

This one's a little harder. Given a PolarPlot, you can obtain its AbstractRenderer and set the shape. For example,

PolarPlot plot = (PolarPlot) chart.getPlot();
AbstractRenderer ar = (AbstractRenderer) plot.getRenderer();
ar.setSeriesShape(0, ShapeUtilities.createDiamond(5), true);

The diamond will appear in the legend, but the DefaultPolarItemRenderer neither renders shapes, nor provides line control. You'd have to extend the default renderer and override drawSeries(). XYLineAndShapeRenderer is good example for study; you can see how it's used in TimeSeriesChartDemo1.

If this is terra incognita to you, I'd recommend The JFreeChart Developer Guide.

Disclaimer: Not affiliated with Object Refinery Limited; I'm a satisfied customer and very minor contributor.

trashgod
(oops, didn't know the formatting messes up in here)
billynomates
A: 

Hey thanks for your reply! I think I'm getting it. So I overrode the drawSeries() method like you said:

public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) {

        double theta = 10;
        double radius = 1;

        p = plot.translateValueThetaRadiusToJava2D(theta, radius, dataArea);

        g2.draw(new Ellipse2D.Double(p.x, p.y, 50, 50));
}

But I get a NullPointerException for that last line. Not sure why. dataArea is chartPanel.getScreenDataArea(), yeah?

billynomates
You can edit your post to elaborate on your question. You may need to look in a debugger to see which reference is null.
trashgod
No, `dataArea` is the plot area, trimmed of insets. http://www.jfree.org/jfreechart/api/javadoc/src-html/org/jfree/chart/plot/PolarPlot.html#line.710
trashgod
Thanks for pointing me in the right direction dude, I've got it working.
billynomates
+1  A: 

So the DefaultPolarItemRenderer takes in all the polar points, converts the polar points to regular Java2D coordinates, makes a Polygon with those points and then draws it. Here's how I got it to draw dots instead of a polygon:

public class MyDefaultPolarItemRenderer extends DefaultPolarItemRenderer {

    @Override
    public void drawSeries(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) {


        int numPoints = dataset.getItemCount(seriesIndex);
        for (int i = 0; i < numPoints; i++) {

            double theta = dataset.getXValue(seriesIndex, i);
            double radius = dataset.getYValue(seriesIndex, i);
            Point p = plot.translateValueThetaRadiusToJava2D(theta, radius,
                    dataArea);
            Ellipse2D el = new Ellipse2D.Double(p.x, p.y, 5, 5);
            g2.fill(el);
            g2.draw(el);
        }
    }
}

and then instantiated this class elsewhere:

    MyDefaultPolarItemRenderer dpir = new MyDefaultPolarItemRenderer();
    dpir.setPlot(plot);
    plot.setRenderer(dpir);
billynomates