예제 #1
0
 public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) {
   HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
   for (int j = 0; j < games.size(); j++) {
     Game game = games.get(j);
     if (game == null) {
       continue;
     }
     for (String key : game.getVarData().keySet()) {
       if (datasets.containsKey(key)) {
         try {
           datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
         } catch (Exception e) {
         }
       } else {
         datasets.put(key, new XYSeriesCollection());
         datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
       }
     }
   }
   HashMap<String, ChartPanel> chartPanels = new HashMap<>();
   for (String key : datasets.keySet()) {
     JFreeChart chart =
         ChartFactory.createXYLineChart(
             key, // chart title
             "X", // x axis label
             "Y", // y axis label
             datasets.get(key), // data
             PlotOrientation.VERTICAL,
             false, // include legend
             true, // tooltips
             false // urls
             );
     XYPlot plot = chart.getXYPlot();
     XYItemRenderer rend = plot.getRenderer();
     for (int i = 0; i < games.size(); i++) {
       Game g = games.get(i);
       if (g.getWinner() == 1) {
         rend.setSeriesPaint(i, Color.RED);
       }
       if (g.getWinner() == 2) {
         rend.setSeriesPaint(i, Color.BLACK);
       }
       if (g.getWinner() == 0) {
         rend.setSeriesPaint(i, Color.PINK);
       }
     }
     ChartPanel chartPanel = new ChartPanel(chart);
     chartPanels.put(key, chartPanel);
   }
   return chartPanels;
 }
예제 #2
0
  public static void createGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (Game game : games) {
      for (String key : game.getVarData().keySet()) {
        if (datasets.containsKey(key)) {
          try {
            datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
          } catch (Exception e) {
          }
        } else {
          datasets.put(key, new XYSeriesCollection());
          datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
        }
      }
    }

    for (String key : datasets.keySet()) {
      JFrame f = new JFrame();
      JFreeChart chart =
          ChartFactory.createXYLineChart(
              key, // chart title
              "X", // x axis label
              "Y", // y axis label
              datasets.get(key), // data
              PlotOrientation.VERTICAL,
              false, // include legend
              true, // tooltips
              false // urls
              );
      XYPlot plot = chart.getXYPlot();
      XYItemRenderer rend = plot.getRenderer();
      for (int i = 0; i < games.size(); i++) {
        Game g = games.get(i);
        if (g.getWinner() == 1) {
          rend.setSeriesPaint(i, Color.RED);
        }
        if (g.getWinner() == 2) {
          rend.setSeriesPaint(i, Color.BLACK);
        }
        if (g.getWinner() == 0) {
          rend.setSeriesPaint(i, Color.PINK);
        }
      }
      ChartPanel chartPanel = new ChartPanel(chart);
      f.setContentPane(chartPanel);
      f.pack();
      RefineryUtilities.centerFrameOnScreen(f);
      f.setVisible(true);
    }
  }