在 JFreeChart 中创建一个简单的箱线图

Create a simple boxplot in JFreeChart

我无法将我的数据集转换为正确的格式以使用 JFreeChart 创建盒须图:

我看过几个在列表中创建数组的示例,但我只有两个列表,所以我想我可以将它们添加到数据集中。但是我只得到一张空白图表(因为我可以看到图表但上面没有数据)。没有错误,只是没有绘制任何内容。有人能告诉我如何获得正确形状的数据吗? 数据集包含一个构造如下的多维数组:

 final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
               List<List<Double>> Overall = new ArrayList<List<Double>>();
               double[] weights_LArr = new double[weights_L.size()];
               double[] weights_RArr = new double[weights_R.size()];
               List<Double> listL = new ArrayList<Double>();
               List<Double> listR = new ArrayList<Double>();

                              for ( int i = 0; i < weights_LArr.length; i++) {
                                weights_LArr[i] = weights_L.get(i);                
                                listL.add(weights_L.get(i));  
                              }



                            for ( int i = 0; i < weights_RArr.length; i++) {
                                weights_RArr[i] = weights_R.get(i); 
                                listR.add(weights_R.get(i));    
                              }        

                    Overall.add(listL);
                    Overall.add(listR);
                    dataset.add(Overall, "Type ", " Number ");



final BoxAndWhiskerCategoryDataset datasetBW = dataset;

         final CategoryAxis xAxis = new CategoryAxis("Type");
         final NumberAxis yAxis = new NumberAxis("Value");
         yAxis.setAutoRangeIncludesZero(false);
         final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
         renderer.setFillBox(false);
         final CategoryPlot plot = new CategoryPlot(datasetBW, xAxis, yAxis, renderer);
         final JFreeChart chart = new JFreeChart(
                            "Box-and-Whisker Demo",
                            new Font("SansSerif", Font.BOLD, 14),
                            plot,
                            true
                        );
        final ChartPanel chartPanel = new ChartPanel(chart);
                     // ChartPanel chartpanel = new ChartPanel(chart);
                    chartPanel.setDomainZoomable(true);

                    JPanel jPanel4 = new JPanel();
                    jPanel4.setLayout(new BorderLayout());
                    jPanel4.add(chartPanel, BorderLayout.NORTH);

                    JFrame frame = new JFrame();
                    frame.add(jPanel4);
                    frame.pack();
                    frame.setVisible(true);

数据集的 add() method expects a List<E> of values, not a List<List<E>>. Looking at this ,尝试这样的操作:

dataset.add(listL, "Weights", "Left");
dataset.add(listR, "Weights", "Right");