@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
    }
  /**
   * Creates a sample chart.
   *
   * @param index the chart index.
   * @param dataset the dataset.
   * @return A chart.
   */
  private JFreeChart createChart(int index, XYDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Chart " + (index + 1), // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL,
            false, // include legend
            false, // tooltips
            false // urls
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setShapesFilled(true);
    // change the auto tick unit selection to integer units only...
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
Esempio n. 3
0
  public String creatchat(CategoryDataset cr, int ss) {
    JFreeChart chart =
        ChartFactory.createLineChart(
            "先来先服务", "进程", "时间", cr, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot ccc = (CategoryPlot) chart.getPlot();

    // Plot plo=chart.getPlot();
    // plo.setDrawingSupplier(getSupplier());

    ValueAxis valueaxis = ccc.getRangeAxis(); // getRangeAxis();
    // 数据为整型
    valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // 设定显示范围,即总是显示1-10
    if (ss == 1) {
      Image image;
      try {
        image = ImageIO.read(new File("C:/wancheng.png"));
        chart.setBackgroundImage(image);
        chart.setBackgroundImageAlpha(1.0f);
        chart.setBorderPaint(Color.white);
        ccc.setBackgroundPaint(null);
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      valueaxis.setLowerBound(-1);
      valueaxis.setUpperBound(7);
    } else {
      valueaxis.setLowerBound(-1);
      valueaxis.setUpperBound(7);
    }
    CategoryItemRenderer renderer = ccc.getRenderer();
    renderer.setSeriesPaint(0, Color.YELLOW);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.gray);
    renderer.setSeriesPaint(4, Color.cyan);
    renderer.setSeriesPaint(5, Color.magenta);
    renderer.setSeriesPaint(6, Color.pink);

    FileOutputStream fos_jpg = null;
    try {
      if (ss == 1) {
        String chaername = "C:/jincheng.png";
        fos_jpg = new FileOutputStream(chaername);

        // 将报表保存为png文件
        ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 510);
        return chaername;
      } else {
        String chaername = "C:/wancheng.png";
        fos_jpg = new FileOutputStream(chaername);

        // 将报表保存为png文件
        ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 510);
        return chaername;
      }

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    } finally {
      try {
        fos_jpg.close();
        System.out.println("create time-createTimeXYChar.");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }