JFreeChart connect one point to all other around

前端 未结 1 805
谎友^
谎友^ 2020-12-21 11:11

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

相关标签:
1条回答
  • 2020-12-21 11:38

    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);
            …
        }
    }
    
    0 讨论(0)
提交回复
热议问题