Ejemplo n.º 1
1
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createBarChart(
           "Bar Chart Demo 1",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setDomainGridlinesVisible(true);
   categoryplot.setRangeCrosshairVisible(true);
   categoryplot.setRangeCrosshairPaint(Color.blue);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setDrawBarOutline(false);
   GradientPaint gradientpaint =
       new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
   GradientPaint gradientpaint1 =
       new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
   GradientPaint gradientpaint2 =
       new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
   barrenderer.setSeriesPaint(0, gradientpaint);
   barrenderer.setSeriesPaint(1, gradientpaint1);
   barrenderer.setSeriesPaint(2, gradientpaint2);
   barrenderer.setLegendItemToolTipGenerator(
       new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setCategoryLabelPositions(
       CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
   return jfreechart;
 }
  /**
   * Creates a chart.
   *
   * @return A chart.
   */
  private static JFreeChart createChart(String symbol) {

    CategoryDataset dataset1 = createDataset1(symbol);
    NumberAxis rangeAxis1 = new NumberAxis("Jumlah");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2(symbol);
    NumberAxis rangeAxis2 = new NumberAxis("Jumlah");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Tahun Periksa");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    //             CombinedCategoryPlot plot = new CombinedCategoryPlot(
    //                     domainAxis, new NumberAxis("Range"));
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    JFreeChart result = new JFreeChart("", new Font("SansSerif", Font.BOLD, 10), plot, true);
    return result;
  }
  /**
   * Creates a chart.
   *
   * @return A chart.
   */
  private static JFreeChart createChart() {

    CategoryDataset dataset1 = createDataset1();
    NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2();
    NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Category");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    JFreeChart chart =
        new JFreeChart(
            "Combined Domain Category Plot Demo", new Font("SansSerif", Font.BOLD, 12), plot, true);
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
  protected void configurePlot(Plot plot, JRChartPlot jrPlot) {

    super.configurePlot(plot, jrPlot);

    if (plot instanceof CategoryPlot) {
      CategoryPlot categoryPlot = (CategoryPlot) plot;
      CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
      CategoryDataset categoryDataset = categoryPlot.getDataset();
      if (categoryDataset != null) {
        for (int i = 0; i < categoryDataset.getRowCount(); i++) {
          categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }
      }
      categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
      categoryPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
      categoryPlot.setDomainGridlinesVisible(false);
      categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    } else if (plot instanceof XYPlot) {
      XYPlot xyPlot = (XYPlot) plot;
      XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
      XYDataset xyDataset = xyPlot.getDataset();
      if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
          xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }
      }
      xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
      xyPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
      xyPlot.setDomainGridlinesVisible(false);
      xyPlot.setRangeZeroBaselineVisible(true);
    }
  }
    @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
    }
Ejemplo n.º 6
0
 private static JFreeChart createChart(CategoryDataset paramCategoryDataset) {
   JFreeChart localJFreeChart =
       ChartFactory.createAreaChart(
           "Area Chart",
           "Category",
           "Value",
           paramCategoryDataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   localJFreeChart.setBackgroundPaint(Color.white);
   TextTitle localTextTitle =
       new TextTitle(
           "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
   localTextTitle.setPosition(RectangleEdge.TOP);
   localTextTitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05D, 0.05D, 0.05D, 0.05D));
   localTextTitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
   localJFreeChart.addSubtitle(localTextTitle);
   CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
   localCategoryPlot.setForegroundAlpha(0.5F);
   localCategoryPlot.setDomainGridlinesVisible(true);
   CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
   localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
   localCategoryAxis.setLowerMargin(0.0D);
   localCategoryAxis.setUpperMargin(0.0D);
   localCategoryAxis.addCategoryLabelToolTip("Type 1", "The first type.");
   localCategoryAxis.addCategoryLabelToolTip("Type 2", "The second type.");
   localCategoryAxis.addCategoryLabelToolTip("Type 3", "The third type.");
   NumberAxis localNumberAxis = (NumberAxis) localCategoryPlot.getRangeAxis();
   localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   localNumberAxis.setLabelAngle(0.0D);
   ChartUtilities.applyCurrentTheme(localJFreeChart);
   return localJFreeChart;
 }
Ejemplo n.º 7
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createchart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 1", // chart
            // title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    //
    // > http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    // renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

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

    return chart;
  }
Ejemplo n.º 8
0
  private void initCharts() {
    dataset = new DefaultCategoryDataset();

    // XY:s
    NumberAxis rangeAxis1 = new NumberAxis("Values");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    trendPlot = new CategoryPlot(dataset, null, rangeAxis1, renderer1);
    trendPlot.setDomainGridlinesVisible(true);

    // Box:
    NumberAxis rangeAxis2 = new NumberAxis("Values");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    sizePlot = new CategoryPlot(dataset, null, rangeAxis2, renderer2);
    sizePlot.setDomainGridlinesVisible(true);
  }
Ejemplo n.º 9
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "", // chart
            // title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
  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;
  }
Ejemplo n.º 11
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "SubCategoryAxis Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    SubCategoryAxis axis = new SubCategoryAxis(null);
    axis.addSubCategory("S1");
    axis.addSubCategory("S2");
    axis.addSubCategory("S3");
    plot.setDomainAxis(axis);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartUtilities.applyCurrentTheme(chart);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    return chart;
  }
Ejemplo n.º 12
0
 private static JFreeChart createChart(String s, CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createBarChart(
           s, "Category", "Value", categorydataset, PlotOrientation.VERTICAL, false, true, false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setDomainGridlinesVisible(true);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
   barrenderer.setDrawBarOutline(false);
   GradientPaint gradientpaint =
       new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
   GradientPaint gradientpaint1 =
       new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
   GradientPaint gradientpaint2 =
       new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
   barrenderer.setSeriesPaint(0, gradientpaint);
   barrenderer.setSeriesPaint(1, gradientpaint1);
   barrenderer.setSeriesPaint(2, gradientpaint2);
   return jfreechart;
 }
Ejemplo n.º 13
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            "Public Opinion : Torture of Prisoners",
            "Country", // domain axis label
            "%", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setMargin(2.0, 0.0, 0.0, 0.0);

    TextTitle tt =
        new TextTitle(
            "Source: http://news.bbc.co.uk/1/hi/world/6063386.stm",
            new Font("Dialog", Font.PLAIN, 11));
    tt.setPosition(RectangleEdge.BOTTOM);
    tt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    tt.setMargin(0.0, 0.0, 4.0, 4.0);
    chart.addSubtitle(tt);

    TextTitle t =
        new TextTitle(
            "(*) Across 27,000 respondents in 25 countries", new Font("Dialog", Font.PLAIN, 11));
    t.setPosition(RectangleEdge.BOTTOM);
    t.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    t.setMargin(4.0, 0.0, 2.0, 4.0);
    chart.addSubtitle(t);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LegendItemCollection items = new LegendItemCollection();
    items.add(
        new LegendItem(
            "Against all torture",
            null,
            null,
            null,
            new Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0),
            Color.green));
    items.add(
        new LegendItem(
            "Some degree permissible",
            null,
            null,
            null,
            new Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0),
            Color.red));
    plot.setFixedLegendItems(items);
    plot.setInsets(new RectangleInsets(5, 5, 5, 20));
    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.0);

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    Paint gp1 = new Color(0, 0, 0, 0);
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    // renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(0, Color.green);
    renderer.setSeriesPaint(1, gp1);
    // renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(2, Color.red);

    return chart;
  }
  /**
   * Returns a sequence plot as a ChartPanel.
   *
   * @param aProteinSequencePanelParent the protein sequence panel parent
   * @param sparklineDataset the dataset
   * @param proteinAnnotations the protein annotations
   * @param addReferenceLine if true, a reference line is added
   * @param allowZooming if true, the user can zoom in the created plot/chart
   * @return a sequence plot
   */
  public ChartPanel getSequencePlot(
      ProteinSequencePanelParent aProteinSequencePanelParent,
      JSparklinesDataset sparklineDataset,
      HashMap<Integer, ArrayList<ResidueAnnotation>> proteinAnnotations,
      boolean addReferenceLine,
      boolean allowZooming) {

    this.proteinSequencePanelParent = aProteinSequencePanelParent;
    DefaultCategoryDataset barChartDataset = new DefaultCategoryDataset();
    StackedBarRenderer renderer = new StackedBarRenderer();
    renderer.setShadowVisible(false);
    CategoryToolTipGenerator myTooltips = new ProteinAnnotations(proteinAnnotations);

    // add the data
    for (int i = 0; i < sparklineDataset.getData().size(); i++) {

      JSparklinesDataSeries sparklineDataSeries = sparklineDataset.getData().get(i);

      for (int j = 0; j < sparklineDataSeries.getData().size(); j++) {
        barChartDataset.addValue(sparklineDataSeries.getData().get(j), "" + i, "" + j);
        renderer.setSeriesPaint(i, sparklineDataSeries.getSeriesColor());
        renderer.setSeriesToolTipGenerator(i, myTooltips);
      }
    }

    // create the chart
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            null, null, null, barChartDataset, PlotOrientation.HORIZONTAL, false, false, false);

    // fine tune the chart properites
    CategoryPlot plot = chart.getCategoryPlot();

    // remove space before/after the domain axis
    plot.getDomainAxis().setUpperMargin(0);
    plot.getDomainAxis().setLowerMargin(0);

    // remove space before/after the range axis
    plot.getRangeAxis().setUpperMargin(0);
    plot.getRangeAxis().setLowerMargin(0);

    renderer.setRenderAsPercentages(true);
    renderer.setBaseToolTipGenerator(new IntervalCategoryToolTipGenerator());

    // add the dataset to the plot
    plot.setDataset(barChartDataset);

    // hide unwanted chart details
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);

    // add a reference line in the middle of the dataset
    if (addReferenceLine) {
      DefaultCategoryDataset referenceLineDataset = new DefaultCategoryDataset();
      referenceLineDataset.addValue(1.0, "A", "B");
      plot.setDataset(1, referenceLineDataset);
      LayeredBarRenderer referenceLineRenderer = new LayeredBarRenderer();
      referenceLineRenderer.setSeriesBarWidth(0, referenceLineWidth);
      referenceLineRenderer.setSeriesFillPaint(0, referenceLineColor);
      referenceLineRenderer.setSeriesPaint(0, referenceLineColor);
      plot.setRenderer(1, referenceLineRenderer);
    }

    // set up the chart renderer
    plot.setRenderer(0, renderer);

    // hide the outline
    chart.getPlot().setOutlineVisible(false);

    // make sure the background is the same as the panel
    chart.getPlot().setBackgroundPaint(backgroundColor);
    chart.setBackgroundPaint(backgroundColor);

    final HashMap<Integer, ArrayList<ResidueAnnotation>> blockTooltips = proteinAnnotations;

    // create the chart panel
    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.addChartMouseListener(
        new ChartMouseListener() {

          @Override
          public void chartMouseClicked(ChartMouseEvent cme) {
            if (cme.getEntity() != null && cme.getTrigger().getButton() == MouseEvent.BUTTON1) {

              ((CategoryItemEntity) cme.getEntity()).getDataset();
              Integer blockNumber =
                  new Integer((String) ((CategoryItemEntity) cme.getEntity()).getRowKey());

              ArrayList<ResidueAnnotation> annotation = blockTooltips.get(blockNumber);
              if (annotation != null) {
                proteinSequencePanelParent.annotationClicked(annotation, cme);
              }
            }
          }

          @Override
          public void chartMouseMoved(ChartMouseEvent cme) {

            cme.getTrigger()
                .getComponent()
                .setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

            if (cme.getEntity() != null && cme.getEntity() instanceof CategoryItemEntity) {
              ((CategoryItemEntity) cme.getEntity()).getDataset();
              Integer blockNumber =
                  new Integer((String) ((CategoryItemEntity) cme.getEntity()).getRowKey());

              ArrayList<ResidueAnnotation> annotation = blockTooltips.get(blockNumber);
              if (annotation != null && !annotation.isEmpty()) {
                if (blockTooltips.get(blockNumber).get(0).isClickable()) {
                  cme.getTrigger()
                      .getComponent()
                      .setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
                }
              }
            }
          }
        });

    if (!allowZooming) {
      chartPanel.setPopupMenu(null);
      chartPanel.setRangeZoomable(false);
    }

    chartPanel.setBackground(Color.WHITE);

    return chartPanel;
  }
 public static JFreeChart createChart() {
   DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
   defaultcategorydataset.addValue(1.0D, "S1", "Category 1");
   defaultcategorydataset.addValue(4D, "S1", "Category 2");
   defaultcategorydataset.addValue(3D, "S1", "Category 3");
   defaultcategorydataset.addValue(5D, "S1", "Category 4");
   defaultcategorydataset.addValue(5D, "S1", "Category 5");
   defaultcategorydataset.addValue(7D, "S1", "Category 6");
   defaultcategorydataset.addValue(7D, "S1", "Category 7");
   defaultcategorydataset.addValue(8D, "S1", "Category 8");
   defaultcategorydataset.addValue(5D, "S2", "Category 1");
   defaultcategorydataset.addValue(7D, "S2", "Category 2");
   defaultcategorydataset.addValue(6D, "S2", "Category 3");
   defaultcategorydataset.addValue(8D, "S2", "Category 4");
   defaultcategorydataset.addValue(4D, "S2", "Category 5");
   defaultcategorydataset.addValue(4D, "S2", "Category 6");
   defaultcategorydataset.addValue(2D, "S2", "Category 7");
   defaultcategorydataset.addValue(1.0D, "S2", "Category 8");
   StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator =
       new StandardCategoryItemLabelGenerator();
   BarRenderer barrenderer = new BarRenderer();
   barrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
   barrenderer.setBaseItemLabelsVisible(true);
   CategoryPlot categoryplot = new CategoryPlot();
   categoryplot.setDataset(defaultcategorydataset);
   categoryplot.setRenderer(barrenderer);
   categoryplot.setDomainAxis(new CategoryAxis("Category"));
   categoryplot.setRangeAxis(new NumberAxis("Value"));
   categoryplot.setOrientation(PlotOrientation.VERTICAL);
   categoryplot.setRangeGridlinesVisible(true);
   categoryplot.setDomainGridlinesVisible(true);
   DefaultCategoryDataset defaultcategorydataset1 = new DefaultCategoryDataset();
   defaultcategorydataset1.addValue(9D, "T1", "Category 1");
   defaultcategorydataset1.addValue(7D, "T1", "Category 2");
   defaultcategorydataset1.addValue(2D, "T1", "Category 3");
   defaultcategorydataset1.addValue(6D, "T1", "Category 4");
   defaultcategorydataset1.addValue(6D, "T1", "Category 5");
   defaultcategorydataset1.addValue(9D, "T1", "Category 6");
   defaultcategorydataset1.addValue(5D, "T1", "Category 7");
   defaultcategorydataset1.addValue(4D, "T1", "Category 8");
   LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
   categoryplot.setDataset(1, defaultcategorydataset1);
   categoryplot.setRenderer(1, lineandshaperenderer);
   NumberAxis numberaxis = new NumberAxis("Axis 2");
   categoryplot.setRangeAxis(1, numberaxis);
   DefaultCategoryDataset defaultcategorydataset2 = new DefaultCategoryDataset();
   defaultcategorydataset2.addValue(94D, "R1", "Category 1");
   defaultcategorydataset2.addValue(75D, "R1", "Category 2");
   defaultcategorydataset2.addValue(22D, "R1", "Category 3");
   defaultcategorydataset2.addValue(74D, "R1", "Category 4");
   defaultcategorydataset2.addValue(83D, "R1", "Category 5");
   defaultcategorydataset2.addValue(9D, "R1", "Category 6");
   defaultcategorydataset2.addValue(23D, "R1", "Category 7");
   defaultcategorydataset2.addValue(98D, "R1", "Category 8");
   categoryplot.setDataset(2, defaultcategorydataset2);
   LineAndShapeRenderer lineandshaperenderer1 = new LineAndShapeRenderer();
   categoryplot.setRenderer(2, lineandshaperenderer1);
   categoryplot.mapDatasetToRangeAxis(2, 1);
   categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
   categoryplot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
   JFreeChart jfreechart = new JFreeChart(categoryplot);
   jfreechart.setTitle("Overlaid Bar Chart");
   return jfreechart;
 }
Ejemplo n.º 16
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);
  }
Ejemplo n.º 17
0
  private String geraTabelaMeses(
      String tituloSLA,
      Integer idAcordoNivelServico,
      HttpServletRequest request,
      UsuarioDTO usuarioDto)
      throws ParseException, IOException {
    ControleGenerateSLAPorAcordoNivelServicoByMesAno
        controleGenerateSLAPorAcordoNivelServicoByMesAno =
            new ControleGenerateSLAPorAcordoNivelServicoByMesAno();
    int m = UtilDatas.getMonth(UtilDatas.getDataAtual());
    int y = UtilDatas.getYear(UtilDatas.getDataAtual());
    int mPesq = (m + 1); // Faz este incremento de 1, pois logo que entrar no laço, faz um -1
    String strTable = "<table width='100%' border='1'>";
    String strHeader = "";
    String strDados = "";
    strHeader += "<tr>";
    strDados += "<tr>";

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 6; i++) {
      mPesq = (mPesq - 1);
      if (mPesq <= 0) {
        mPesq = 12;
        y = y - 1;
      }
      strHeader = strHeader + "<td colspan='2' style='border:1px solid black; text-align:center'>";
      strHeader = strHeader + (mPesq + "/" + y);
      strHeader = strHeader + "</td>";

      List lst =
          controleGenerateSLAPorAcordoNivelServicoByMesAno.execute(idAcordoNivelServico, y, mPesq);
      double qtdeDentroPrazo = 0;
      double qtdeForaPrazo = 0;
      if (lst != null && lst.size() > 0) {
        for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) {
          Object[] objs = (Object[]) itSLA.next();
          if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
            qtdeForaPrazo = (Double) objs[2];
          } else {
            qtdeDentroPrazo = (Double) objs[2];
          }
        }
      }
      double qtdeDentroPrazoPerc = 0;
      if ((qtdeDentroPrazo + qtdeForaPrazo) > 0) {
        qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
      }
      double qtdeForaPrazoPerc = 0;
      if ((qtdeDentroPrazo + qtdeForaPrazo) > 0) {
        qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
      }
      strDados = strDados + "<td style='border:1px solid black'>";
      strDados = strDados + UtilFormatacao.formatDouble(qtdeDentroPrazoPerc, 2) + "%";
      strDados = strDados + "</td>";
      strDados = strDados + "<td style='border:1px solid black'>";
      strDados = strDados + UtilFormatacao.formatDouble(qtdeForaPrazoPerc, 2) + "%";
      strDados = strDados + "</td>";

      dataset.setValue(
          new Double(qtdeDentroPrazoPerc),
          UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo"),
          "" + (mPesq + "/" + y));
      dataset.setValue(
          new Double(qtdeForaPrazoPerc),
          UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo"),
          "" + (mPesq + "/" + y));
    }
    strHeader += "</tr>";
    strDados += "</tr>";

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            tituloSLA, // chart title
            UtilI18N.internacionaliza(request, "sla.avaliacao.indicadores"), // domain axis label
            UtilI18N.internacionaliza(request, "sla.avaliacao.resultado"), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0, 64, 0));

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

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

    String nomeImgAval =
        CITCorporeUtil.caminho_real_app
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLAXX_"
            + idAcordoNivelServico
            + ".png";
    String nomeImgAvalRel =
        br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
            + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLAXX_"
            + idAcordoNivelServico
            + ".png";
    File arquivo2 = new File(nomeImgAval);
    if (arquivo2.exists()) {
      arquivo2.delete();
    }
    ChartUtilities.saveChartAsPNG(arquivo2, chart, 500, 200);
    strTable += "<tr>";
    strTable += "<td colspan='12'>";
    strTable += "<img src='" + nomeImgAvalRel + "' border='0'/>";
    strTable += "</td>";
    strTable += "</tr>";

    strTable += strHeader;
    strTable += strDados;

    strTable += "</table>";
    return strTable;
  }