コード例 #1
0
    @Override
    public void customize(JFreeChart chart, ReportParameters reportParameters) {

      BarRenderer barRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
      // barRenderer.setBaseSeriesVisible(false);//QUITA LAS BARRAS
      // barRenderer.setBaseSeriesVisibleInLegend(false);
      // barRenderer.setDrawBarOutline(false);
      barRenderer.setShadowVisible(false);
      barRenderer.setBarPainter(new CustomBarPainter());
      barRenderer.setItemMargin(0); // QUITA ESPACIOS ENTRE BARRA Y BARRA

      CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
      domainAxis.setUpperMargin(0);
      domainAxis.setLowerMargin(0);
      domainAxis.setCategoryMargin(0);
      domainAxis.setAxisLineVisible(false); // este es util

      Plot plot = chart.getPlot();
      // plot.setOutlineVisible(false);
      plot.setInsets(new RectangleInsets(0, 0, 0, 0)); // este sera util

      CategoryPlot categoryPlot = chart.getCategoryPlot();
      categoryPlot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
      // FAFO6categoryPlot.setRangeGridlinePaint(Color.WHITE);
      categoryPlot.setDomainGridlinesVisible(false);
      // FAFO5categoryPlot.setRangeGridlinesVisible(false);
      // categoryPlot.setBackgroundPaint(Color.white);
      categoryPlot.setOutlineVisible(false);

      ValueAxis valueAsix = categoryPlot.getRangeAxis();
      valueAsix.setAxisLineVisible(false); // este es muy util
      valueAsix.setRange(0, objDatosReporte.getIntMaxRango());
      valueAsix.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // este es muy util
    }
  protected JFreeChart createGanttChart() throws JRException {

    JFreeChart jfreeChart = super.createGanttChart();
    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    categoryPlot.setDomainGridlinesVisible(true);
    categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);
    categoryPlot.setDomainGridlineStroke(
        new BasicStroke(
            0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 50, new float[] {1}, 0));

    categoryPlot.setDomainGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);

    categoryPlot.setRangeGridlinesVisible(true);
    categoryPlot.setRangeGridlineStroke(
        new BasicStroke(
            0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 50, new float[] {1}, 0));

    categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
    //		JRBarPlot barPlot = (BarPlot)categoryPlot;
    //		categoryPlot.getDomainAxis().setTickLabelsVisible(
    //				categoryPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels().
    //				true
    //				);
    CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
    categoryRenderer.setBaseItemLabelsVisible(true);
    BarRenderer barRenderer = (BarRenderer) categoryRenderer;
    List seriesPaints =
        (List) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS);
    barRenderer.setSeriesPaint(0, (Paint) seriesPaints.get(3));
    barRenderer.setSeriesPaint(1, (Paint) seriesPaints.get(0));
    CategoryDataset categoryDataset = categoryPlot.getDataset();
    if (categoryDataset != null) {
      for (int i = 0; i < categoryDataset.getRowCount(); i++) {
        barRenderer.setSeriesItemLabelFont(i, categoryPlot.getDomainAxis().getTickLabelFont());
        barRenderer.setSeriesItemLabelsVisible(i, true);
        //			barRenderer.setSeriesPaint(i, GRADIENT_PAINTS[i]);
        //			CategoryMarker categoryMarker = new
        // CategoryMarker(categoryDataset.getColumnKey(i),MARKER_COLOR, new BasicStroke(1f));
        //			categoryMarker.setAlpha(0.5f);
        //			categoryPlot.addDomainMarker(categoryMarker, Layer.BACKGROUND);
      }
    }
    categoryPlot.setOutlinePaint(Color.DARK_GRAY);
    categoryPlot.setOutlineStroke(new BasicStroke(1.5f));
    categoryPlot.setOutlineVisible(true);
    return jfreeChart;
  }
コード例 #3
0
  private BufferedImage generarGraficoBarrasDistribucionResultados(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      double[] valores,
      String[] funciones,
      boolean porcentaje,
      boolean leyenda,
      int intervaloAprobacion,
      int anchoImagen,
      int altoImagen) {
    if (valores.length != funciones.length) {
      return null;
    }
    DefaultCategoryDataset pieDataset = new DefaultCategoryDataset();
    for (int i = 0; i < valores.length; i++) {
      pieDataset.addValue(valores[i], "Serie 1", funciones[i]);
    }
    JFreeChart chart =
        ChartFactory.createBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            pieDataset,
            PlotOrientation.VERTICAL,
            leyenda,
            true,
            false);
    chart.setBackgroundPaint(null);
    chart.setBorderVisible(false);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    final AprobadoDesaprobadoBarRenderer renderer = new AprobadoDesaprobadoBarRenderer();
    renderer.setIntervaloAprobacion(intervaloAprobacion);
    plot.setRenderer(renderer);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    this.lastChart = chart;

    // Generamos una imagen
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
コード例 #4
0
  /** Comienzo de mètodos básicos. */
  private BufferedImage generarGraficoBarrasApiladas(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      PlotOrientation orientacion,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        dataset.addValue(serie.valores[i], serie.funciones[i], serie.nombre);
      }
    }
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            dataset,
            orientacion,
            leyenda,
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap(series.get(0).nombre);
    for (Serie serie : series) {
      map.mapKeyToGroup(serie.nombre, serie.nombre);
    }
    renderer.setSeriesToGroupMap(map);
    renderer.setDrawBarOutline(false);
    renderer.setRenderAsPercentages(porcentaje);
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          Color color = generarColorAleatorio(Color.orange);
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

    renderer.setGradientPaintTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    domainAxis.setCategoryMargin(0.05);

    plot.setRenderer(renderer);

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
コード例 #5
0
  private BufferedImage generarGraficoBarras(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        barDataset.addValue(serie.valores[i], serie.nombre, serie.funciones[i]);
      }
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            barDataset,
            PlotOrientation.VERTICAL,
            leyenda,
            true,
            false);
    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        Color color = generarColorAleatorio(Color.orange);
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
コード例 #6
0
  public Drawable createChart(ADCDataset dataset, Dimension dimension) {
    JFreeChart chart =
        ChartFactory.createBarChart(
            "", // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            false, // legend
            false, // tooltips
            false // urls
            );
    TextTitle textTitle = new TextTitle(dataset.get(Attribute.TITLE), TITLE_FONT);
    textTitle.setPadding(new RectangleInsets(10, 0, 0, 0));
    chart.setTitle(textTitle);

    chart.addLegend(createLegend(dataset.getRowKey(0).toString(), dataset.getRowKey(1).toString()));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineVisible(false);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlineStroke(new BasicStroke(2));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoTickUnitSelection(true);
    rangeAxis.setTickUnit(new NumberTickUnit(0.2, percentFormatter()));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setLabel(dataset.get(Attribute.Y_AXIS_LABEL));
    rangeAxis.setAxisLineStroke(new BasicStroke(2));
    rangeAxis.setAxisLinePaint(Color.black);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setLabelPaint(AXIS_LABEL_COLOR);
    rangeAxis.setLabelFont(AXIS_LABEL_FONT);
    rangeAxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0));
    rangeAxis.setUpperMargin(0);
    rangeAxis.setAutoRange(false);
    rangeAxis.setRange(0, 1);

    CategoryAxis cAxis = plot.getDomainAxis();
    cAxis.setTickMarksVisible(false);
    cAxis.setAxisLinePaint(Color.black);
    cAxis.setAxisLineStroke(new BasicStroke(2));
    cAxis.setLabel(dataset.get(Attribute.X_AXIS_LABEL));
    cAxis.setTickLabelsVisible(true);
    cAxis.setUpperMargin(0.05);
    cAxis.setLowerMargin(0.05);
    cAxis.setTickLabelFont(CAXIS_LABEL_FONT);
    cAxis.setTickLabelPaint(Color.black);
    CustomBarRenderer renderer = new CustomBarRenderer();
    plot.setRenderer(renderer);
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setMaximumBarWidth(0.08);
    renderer.setItemMargin(0.01);
    return new JFreeChartDrawable(chart, dimension);
  }