JFreeChart连接一个点到所有其他 [英] JFreeChart connect one point to all other around
问题描述
可以将一个点连接到JFreeChart中的所有其他点
这里应该如何看起来
is it possible to connect one point to all others around in JFreeChart
here how it should looks
所有连接到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
作为其系列索引的项的行。
You'll need a custom renderer. This minimal example overrides the XYLineAndShapeRenderer
method drawPrimaryLine()
. It draws the lines relative to the item having anchor
as its series index. You'll need to recapitulate the existing implementation, replacing the lines shown below.
附录:示例只需传递 anchor
作为构造函数参数,但您可以扩展 XYDataset
,为每个系列包含唯一值。
Addendum: The example simply passes anchor
as a constructor parameter, but you can extend XYDataset
to include a unique value for each series.
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);
…
}
}
这篇关于JFreeChart连接一个点到所有其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!