绘制点而不是线? JFreeChart PolarChart [英] Plot points instead of lines? JFreeChart PolarChart
问题描述
当前,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?
我曾尝试使用translateValueThetaRadiusToJava2D()
和Graphics2D绘制圆,但是它很笨重且人为设计.
I have tried using translateValueThetaRadiusToJava2D()
and Graphics2D to draw circles but it's very clunky and contrived.
欢迎提出任何建议!
推荐答案
因此DefaultPolarItemRenderer
接受所有极点,将极点转换为常规Java2D坐标,用这些点制成Polygon
,然后绘制.这是我绘制点而不是多边形的方法:
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);
这篇关于绘制点而不是线? JFreeChart PolarChart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!