What are the dots instead of the lines? JFreeChart PolarChart

Currently, PolarChart combines all coordinates with lines that create a polygon. I just want it to make up each dot with a dot and DO NOT connect them together. Is it possible?

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

Any suggestions are welcome!

+7
plot jfreechart
source share
4 answers

Thus, DefaultPolarItemRenderer accepts at all polar points, converts the polar points to normal Java2D coordinates, makes Polygon with these points, and then draws. Here is how I got this to draw points 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(px, py, 5, 5); g2.fill(el); g2.draw(el); } } } 

and then an instance of this class elsewhere:

  MyDefaultPolarItemRenderer dpir = new MyDefaultPolarItemRenderer(); dpir.setPlot(plot); plot.setRenderer(dpir); 
+7
source share

This is a little trickier. Given PolarPlot , you can get an AbstractRenderer and set the form. For example,

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

A diamond will appear in the legend, but DefaultPolarItemRenderer does not display shapes and does not provide row control. You will have to extend the default rendering and override drawSeries() . XYLineAndShapeRenderer is a good example to learn; you can see how it is used in TimeSeriesChartDemo1 .

If this is terra incognita for you, I would recommend the JFreeChart † Developer's Guide .

† Disclaimer: Not affiliated with Object Refinery Limited; I am a satisfied customer and a very insignificant contributor.

+2
source share

This is a great discussion if you want the function to take the color assigned by the user into a series

add ...

 Color c =(Color)this.lookupSeriesPaint(seriesIndex); g2.setColor(c); 

before...

 g.draw(e1); 

there are other functions ... use the exit code to see what other functions are available for rendereing series with a name starting with lookupSeries........(int seriesindex)

+1
source share

I found a rather strange way to get points without any lines connecting them.

I installed the Stroke renderer - a thin line with a stroke phase of 0 and a length of 1e10:

 Stroke dashedStroke = new BasicStroke( 0.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, new float[] {0.0f, 1e10f}, 1.0f ); renderer.setSeriesStroke(0, dashedStroke); 
+1
source share

All Articles