绘制点而不是线? JFreeChart PolarChart

发布于 2024-08-25 02:47:37 字数 181 浏览 4 评论 0原文

目前,PolarChart 将所有坐标与线条连接起来创建多边形。我只是希望它用一个点绘制每个点而不是将它们连接在一起。这可能吗?

我尝试过使用 translateValueThetaRadiusToJava2D() 和 Graphics2D 来绘制圆圈,但它非常笨拙且做作。

欢迎任何建议!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仙女 2024-09-01 02:47:37

因此,DefaultPolarItemRenderer 接收所有极点,将极点转换为常规 Java2D 坐标,用这些点创建一个 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);
        }
    }
}

然后在其他地方实例化此类:

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

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);
机场等船 2024-09-01 02:47:37

这个有点难。给定一个PolarPlot,您可以获得其AbstractRenderer 并设置形状。例如,

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

菱形将出现在图例中,但 DefaultPolarItemRenderer 既不渲染形状,也不提供线条控制。您必须扩展默认渲染器并覆盖drawSeries()XYLineAndShapeRenderer 是很好的学习例子;您可以在 中查看它的使用方式TimeSeriesChartDemo1

如果这对您来说是未知领域,我会推荐 JFreeChart 开发人员指南

免责声明:不隶属于 Object Refinery Limited;我是一位满意的客户,也是一个很小的贡献者。

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.

何时共饮酒 2024-09-01 02:47:37

这是一个很好的讨论,如果您希望该函数获取用户分配给系列的颜色,则

添加...

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

之前...

g.draw(e1);

还有其他函数...使用代码完成来查看针对系列还有哪些可用的函数渲染名称从 lookupSeries........(int seriesindex)

This is an excellent discussion, in case you want the function to pick up the color assigned by user to the series

add ...

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

before ...

g.draw(e1);

there are other functions... use code completion to see what else functions are available against series rendereing with name starting from lookupSeries........(int seriesindex)

抚你发端 2024-09-01 02:47:37

我发现了一种相当奇怪的方法来获取点,而无需任何线连接它们。

我设置了 Stroke渲染器 是一条细线,破折号相位为 0,长度为 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);

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

I set the Stroke of the renderer to be a thin line, with a dash phase of 0, and 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文