Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

java - JFreeChart connect one point to all other around

is it possible to connect one point to all others around in JFreeChart
here how it should looks enter image description here

so all the points around connected to X point

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Addendum: The example simply passes anchor as a constructor parameter, but you can extend XYDataset to include a unique value for each series.

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);
        …
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...