Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot points instead of lines? JFreeChart PolarChart

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!

like image 234
MSpeed Avatar asked Mar 12 '10 16:03

MSpeed


1 Answers

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);
like image 185
MSpeed Avatar answered Sep 17 '22 11:09

MSpeed