我有一个jfree图表,可以在每次运行代码时生成。
现在,我想在同一张图表上覆盖几个蜘蛛图。请帮我怎么做

java - 如何在现有的JfreeChart上方绘制蜘蛛图-LMLPHP

在此之上,我需要使用jfree添加另一个蜘蛛图。

这是我做这张图表的代码。

package com.rectrix.exide.pdfbox;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;

import javax.swing.JPanel;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.*;

public class DemoChart extends ApplicationFrame {

    public DemoChart(String s)
    {
        super(s);
        JPanel jpanel = createDemoPanel();
        jpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(jpanel);
    }

    private static CategoryDataset createDataset()
    {


        String s1 = "First";
        String s2 = "Second";
        String s3 = "Third";
        String s4 = "Forth";
        String s5 = "Fivth";
        String s6 = "Sixth";
        String s7 = "Seventh";
        String s8 = "Eighth";
        String s9 = "Ninth";
        String s10 = "Tenth";

        DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
        int count = 5;
        int value = 0;
        //String keyRow="s";
        for (int i=1;i<=10;i++){
            value = i*4;
            Comparable colKey = 0;
            String keyRow = "s"+i;
            for(int j=1;j<=count;j++){
            colKey = j;
                defaultcategorydataset.addValue(value, keyRow, colKey);
            }
        }
return defaultcategorydataset;
    }

    public static JFreeChart createChart1(CategoryDataset categorydataset,double d) {
        SpiderWebPlot plot = new SpiderWebPlot(categorydataset);
        Color bckColor1 = Color.decode("#4282CE"); //Light blue
        Paint p = new GradientPaint(0, 1, bckColor1, 0, 1, bckColor1);
        plot.setSeriesPaint(p);
        JFreeChart chart = new JFreeChart("", plot);
        return chart;
    }


    public static JPanel createDemoPanel()
    {
        JFreeChart jfreechart = createChart1(createDataset(), 10D);
        return new ChartPanel(jfreechart);
    }

    public static void main(String args[])
    {
        DemoChart spiderwebchartdemo1 = new DemoChart("JFreeChart: SpiderWebChartDemo1.java");
        spiderwebchartdemo1.pack();
        RefineryUtilities.centerFrameOnScreen(spiderwebchartdemo1);
        spiderwebchartdemo1.setVisible(true);
    }
}


请尽快帮助我,我需要在明天之前发送此版本
在此先感谢您的帮助和努力。

最佳答案

我想在同一张图表上覆盖几个蜘蛛图。


检查spider web plot如何用于显示多元数据可能会有所帮助。下面的简化示例仅比较两个OBSERVATIONS,每个都有五个名为VARIABLESA .. E,且随机值在1 .. 3范围内。偶然地,变量B的值重合;其余的不同。您可以调整OBSERVATIONS的值以查看效果,但是随着观察数量的增加,结果变得越来越混乱。您可能要按照建议的here更改系列可见性,或考虑使用这些alternatives

java - 如何在现有的JfreeChart上方绘制蜘蛛图-LMLPHP

import java.awt.EventQueue;
import java.util.Random;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;

/** @see https://stackoverflow.com/a/32885067/230513 */
public class SpiderChart extends ApplicationFrame {

    private static final int OBSERVATIONS = 2;
    private static final int VARIABLES = 5;
    private static final Random r = new Random();

    public SpiderChart(String s) {
        super(s);
        add(createDemoPanel());
    }

    private static CategoryDataset createDataset() {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 1; i <= OBSERVATIONS; i++) {
            String rowKey = "Observation " + i;
            for (int j = 1; j <= VARIABLES; j++) {
                Comparable colKey = Character.valueOf((char)(j+64));
                dataset.addValue(r.nextInt(3) + 1, rowKey, colKey);
            }
        }
        return dataset;
    }

    public static JFreeChart createChart(CategoryDataset dataset) {
        SpiderWebPlot plot = new SpiderWebPlot(dataset);
        JFreeChart chart = new JFreeChart("Test", plot);
        return chart;
    }

    public static JPanel createDemoPanel() {
        JFreeChart jfreechart = createChart(createDataset());
        return new ChartPanel(jfreechart);
    }

    public static void main(String args[]) {
        EventQueue.invokeLater(() -> {
            SpiderChart demo = new SpiderChart("SpiderWebChart");
            demo.pack();
            demo.setDefaultCloseOperation(EXIT_ON_CLOSE);
            demo.setVisible(true);
        });
    }
}

10-06 09:06