@Override
 protected void afterPlot(List<? super InstanceStatistics> list, JFreeChart chart, XYPlot plot) {
   NumberAxis sizeAxis = (NumberAxis) plot.getRangeAxis(0);
   Font labelFont = sizeAxis.getLabelFont();
   Paint labelPaint = sizeAxis.getLabelPaint();
   TimeSeries tm = new TimeSeries("memory");
   for (int i = 0; i < list.size(); i++) {
     double memory = 0;
     MapStatistics mapStatistics = (MapStatistics) list.get(i);
     for (MapStatistics.LocalMapStatistics localMapStatistics :
         mapStatistics.getListOfLocalStats()) {
       memory =
           memory
               + localMapStatistics.ownedEntryMemoryCost
               + localMapStatistics.backupEntryMemoryCost
               + localMapStatistics.markedAsRemovedMemoryCost;
     }
     double mem = new Double(memory / (double) (1024 * 1024));
     tm.addOrUpdate(new Second(((MapStatistics) list.get(i)).getCreatedDate()), mem);
   }
   NumberAxis memoryAxis = new NumberAxis("memory (MB)");
   memoryAxis.setAutoRange(true);
   memoryAxis.setAutoRangeIncludesZero(false);
   plot.setDataset(1, new TimeSeriesCollection(tm));
   plot.setRangeAxis(1, memoryAxis);
   plot.mapDatasetToRangeAxis(1, 1);
   plot.setRenderer(1, new StandardXYItemRenderer());
   plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
   increaseRange(memoryAxis);
   memoryAxis.setLabelFont(labelFont);
   memoryAxis.setLabelPaint(labelPaint);
 }
Esempio n. 2
0
  public JPanel createChart(
      Date from,
      Date to,
      StockInfo stock1,
      StockInfo stock2,
      Color color1,
      Color color2,
      StockPriceType priceType) {

    LOG.info(
        "Generating chart for tickers:"
            + stock1.getTickerSymbol()
            + " & "
            + stock2.getTickerSymbol());

    String chartTitle = df.format(from) + " to " + df.format(to) + " " + priceType;
    XYDataset dataset1 = createDataset(stock1, priceType);
    XYDataset dataset2 = createDataset(stock2, priceType);

    JFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            chartTitle,
            DOMAIN_AXIS_TITLE,
            stock1.getTickerSymbol() + RANGE_AXIS_SUFFIX,
            dataset1,
            true,
            true,
            false);

    XYPlot plot = chart.getXYPlot();
    NumberAxis axis2 = new NumberAxis(stock2.getTickerSymbol() + RANGE_AXIS_SUFFIX);
    Font tickLabelFont = axis2.getTickLabelFont().deriveFont(11.0F);
    Font labelFont = axis2.getLabelFont().deriveFont(15.0F).deriveFont(Font.BOLD);
    axis2.setTickLabelFont(tickLabelFont);
    axis2.setLabelFont(labelFont);
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    StandardXYItemRenderer renderer = new StandardXYItemRenderer();
    renderer.setSeriesPaint(0, color1);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(renderer);

    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, color2);
    renderer2.setBaseShapesVisible(true);
    renderer2.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(df);

    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
  }
  /**
   * Add axis
   *
   * @param name new axis name
   */
  @Override
  public final void addAxis(String name) {
    boolean encontrado = false;
    for (AxisChart categoria : axes) {
      if (categoria.getName().equals(name)) {
        encontrado = true;
        break;
      }
    }
    if (!encontrado) {
      axes.add(new AxisChart((name)));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    NumberAxis ejeOrdenada = new NumberAxis(name);

    ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    ejeOrdenada.setLabelFont(ejeOrdenada.getLabelFont().deriveFont(fontSize));
    ejeOrdenada.setTickLabelFont(ejeOrdenada.getLabelFont().deriveFont(fontSize));

    int i = datasetList.size();

    datasetList.add(dataset);
    AxesList.add(ejeOrdenada);
    plot.setDataset(i, dataset);
    plot.setRangeAxis(i, ejeOrdenada);
    plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT);
    plot.mapDatasetToRangeAxis(i, i);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, true);
    if (i == 0) {
      plot.setRenderer(renderer);
    } else {
      plot.setRenderer(i, renderer);
    }

    final LegendAxis le;
    final int indiceLeyenda = legendFrame.getChildren().size();

    legendFrame.getChildren().add(le = new LegendAxis(name));

    le.setOnMouseClicked(
        (MouseEvent t) -> {
          if (le.selected && t.getClickCount() == 2) {
            setOrdinateRange(AxesList.get(indiceLeyenda));
          }
        });

    le.setOnMouseEntered(
        (MouseEvent t) -> {
          le.setStyle("-fx-background-color:blue");
          le.selected = true;
          AxesList.get(indiceLeyenda)
              .setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web("blue")));
          AxesList.get(indiceLeyenda)
              .setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web("blue")));
        });

    le.setOnMouseExited(
        (MouseEvent t) -> {
          le.setStyle("-fx-background-color:" + strBackgroundColor);
          le.selected = false;
          AxesList.get(indiceLeyenda)
              .setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
          AxesList.get(indiceLeyenda)
              .setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
        });
  }