gpt4 book ai didi

java - JFreeChart 将一个点连接到周围的所有其他点

转载 作者:行者123 更新时间:2023-11-30 08:14:55 29 4
gpt4 key购买 nike

在 JFreeChart 中是否可以将一个点连接到周围的所有其他点
它应该是这样的 enter image description here

所以周围所有的点都连接到X点

chart.setBackgroundPaint(Color.white);

final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
Shape somehing = ShapeUtilities.createDiamond(4);



final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesLinesVisible(0, false);
renderer.setSeriesLinesVisible(1, false);
renderer.setSeriesLinesVisible(2, false);
renderer.setSeriesLinesVisible(3, false);

renderer.setSeriesShape(0, cross);
renderer.setSeriesShape(1, somehing);
renderer.setSeriesShape(2, somehing);
renderer.setSeriesShape(3, somehing);

renderer.setSeriesPaint(0, Color.RED);
renderer.setSeriesPaint(1, Color.BLUE);
renderer.setSeriesPaint(2, Color.YELLOW);
renderer.setSeriesPaint(2, Color.green);
plot.setRenderer(renderer);


plot.setBackgroundPaint(Color.BLACK);
// change the auto tick unit selection to integer units only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// OPTIONAL CUSTOMISATION COMPLETED.

return chart;

谢谢你

最佳答案

您需要一个自定义渲染器。这个最小的例子覆盖了 XYLineAndShapeRenderer方法 drawPrimaryLine()。它绘制相对于以 anchor 作为其系列索引的项目的线条。您需要概括现有的实现,替换下面显示的行。

附录:该示例只是将 anchor 作为构造函数参数传递,但您可以扩展 XYDataset 以包含每个系列的唯一值。

image

MyRenderer r = new MyRenderer(8);
XYPlot plot = new XYPlot(dataset, new NumberAxis("X"), new NumberAxis("Y"), r);
JFreeChart chart = new JFreeChart(plot);

private static class MyRenderer extends XYLineAndShapeRenderer {

private final int anchor;

public MyRenderer(int acnchor) {
this.anchor = acnchor;
}

@Override
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2,
XYPlot plot, XYDataset dataset, int pass, int series, int item,
ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
if (item == anchor) {
return;
}

double x0 = dataset.getXValue(series, anchor);
double y0 = dataset.getYValue(series, anchor);

}
}

关于java - JFreeChart 将一个点连接到周围的所有其他点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29224033/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com