Пример #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);
    }
  }
Пример #3
0
 /**
  * @param games the games to graph
  * @param key the variable to create the graph with
  * @param start if index, the index at which to start, else the percent in the game at which to
  *     start
  * @param stop if index, the index at which to end, else the percent in the game at which to end
  * @param index
  * @return
  */
 public static ChartPanel getCustomGraph(
     Game[] games, String key, double start, double stop, boolean index) {
   XYSeriesCollection dataset = new XYSeriesCollection();
   for (Game game : games) {
     ArrayList<Double> data = game.getVar(key);
     int begin;
     int end;
     if (index) {
       begin = (int) start;
       end = (int) stop;
     } else {
       begin = (int) (data.size() / start);
       end = (int) (data.size() / stop);
     }
     XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId());
     dataset.addSeries(series);
   }
   JFreeChart chart =
       ChartFactory.createXYLineChart(
           key, // chart title
           "X", // x axis label
           "Y", // y axis label
           dataset, // data
           PlotOrientation.VERTICAL,
           false, // include legend
           true, // tooltips
           false // urls
           );
   XYPlot plot = chart.getXYPlot();
   XYItemRenderer rend = plot.getRenderer();
   for (int i = 0; i < games.length; i++) {
     Game g = games[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);
   return chartPanel;
 }