Ejemplo n.º 1
0
  /**
   * Creates a vertical 3D-effect bar chart with default settings.
   *
   * @param title the chart title.
   * @param categoryAxisLabel the label for the category axis.
   * @param valueAxisLabel the label for the value axis.
   * @param data the dataset for the chart.
   * @param legend a flag specifying whether or not a legend is required.
   * @param tooltips configure chart to generate tool tips?
   * @param urls configure chart to generate URLs?
   * @return a vertical 3D-effect bar chart.
   */
  public static JFreeChart createBarChart3D(
      String title,
      java.awt.Font titleFont,
      String categoryAxisLabel,
      String valueAxisLabel,
      CategoryDataset data,
      PlotOrientation orientation,
      boolean legend,
      boolean tooltips,
      boolean urls,
      CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    BarRenderer3D renderer = new BarRenderer3D();

    // renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    if (tooltips) {
      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
      renderer.setItemURLGenerator(urlGenerator);
    }

    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    plot.setForegroundAlpha(0.75f);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;
  }
Ejemplo n.º 2
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.º 3
0
  private JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createBarChart3D(
            "", // Título
            "Planejamento", // Label X
            "Valores", // Label Y
            dataset, // Dados
            PlotOrientation.VERTICAL, // Orientação
            true, // Legenda
            false, // Tooltips
            false // urls
            );

    chart.setBackgroundPaint(new Color(255, 255, 255));
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.6f);

    return chart;
  }
Ejemplo n.º 4
0
  public static String getBarSeries(Map dataSource, String objectName, HttpSession session)
      throws Exception {
    DefaultKeyedValues barValues = new DefaultKeyedValues();
    DefaultKeyedValues seriesValues = new DefaultKeyedValues();
    Element chartObject =
        XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName);

    Element barField = chartObject.getChild("BarFields").getChild("Field");
    Element seriesField = chartObject.getChild("SeriesFields").getChild("Field");

    for (int i = 0; i < dataSource.size(); i++) {
      Map rec = (Map) dataSource.get("ROW" + i);
      barValues.addValue(
          DataFilter.show(rec, chartObject.getChildText("ColumnLabel")),
          Double.parseDouble(rec.get(barField.getAttributeValue("name")).toString()));
      seriesValues.addValue(
          DataFilter.show(rec, chartObject.getChildText("ColumnLabel")),
          Double.parseDouble(rec.get(seriesField.getAttributeValue("name")).toString()));
    }

    CategoryDataset dataset =
        DatasetUtilities.createCategoryDataset(barField.getAttributeValue("label"), barValues);

    PlotOrientation plotOrientation =
        chartObject.getAttributeValue("plotOrientation").equalsIgnoreCase("VERTICAL")
            ? PlotOrientation.VERTICAL
            : PlotOrientation.HORIZONTAL;
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            chartObject.getAttributeValue("title"),
            chartObject.getAttributeValue("categoryAxisLabel"),
            chartObject.getAttributeValue("valueAxisLabel"),
            dataset,
            plotOrientation,
            chartObject.getAttribute("showLegend").getBooleanValue(),
            chartObject.getAttribute("showToolTips").getBooleanValue(),
            chartObject.getAttribute("urls").getBooleanValue());

    CategoryPlot categoryplot = chart.getCategoryPlot();
    LineRenderer3D lineRenderer = new LineRenderer3D();
    CategoryDataset datasetSeries =
        DatasetUtilities.createCategoryDataset(
            seriesField.getAttributeValue("label"), seriesValues);

    categoryplot.setDataset(1, datasetSeries);
    categoryplot.setRangeAxis(1, new NumberAxis3D(seriesField.getAttributeValue("label")));
    categoryplot.setRenderer(1, lineRenderer);
    categoryplot.mapDatasetToRangeAxis(1, 1);

    BarRenderer3D barrenderer = (BarRenderer3D) categoryplot.getRenderer();
    barrenderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    barrenderer.setItemLabelsVisible(true);
    barrenderer.setPositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_CENTER));

    //	        lineRenderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    //	        lineRenderer.setItemLabelsVisible(true);
    //	        lineRenderer.setPositiveItemLabelPosition(
    //	                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER));

    float alpha = 0.7F;
    if (chartObject.getAttribute("alpha") != null) {
      alpha = chartObject.getAttribute("alpha").getFloatValue();
    }
    categoryplot.setForegroundAlpha(alpha);

    int width, height;
    if (chartObject.getAttributeValue("width").equalsIgnoreCase("auto")) {
      width = (50 * dataSource.size()) + 100;
    } else {
      width = Integer.parseInt(chartObject.getAttributeValue("width"));
    }
    if (chartObject.getAttributeValue("height").equalsIgnoreCase("auto")) {
      height = (50 * dataSource.size()) + 100;
    } else {
      height = Integer.parseInt(chartObject.getAttributeValue("height"));
    }

    return ServletUtilities.saveChartAsPNG(chart, width, height, session);
  }
Ejemplo n.º 5
0
  public static String getSimpleBarChart(Map dataSource, String objectName, HttpSession session)
      throws Throwable {
    Element chartObject =
        XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName);

    List invokeFields = chartObject.getChild("InvokeFields").getChildren("Field");
    double[][] data = new double[invokeFields.size()][dataSource.size()];
    String[] rowKeys = new String[invokeFields.size()];
    String[] columnKeys = new String[dataSource.size()];
    String columnLabel = chartObject.getChildText("ColumnLabel");

    for (int i = 0; i < dataSource.size(); i++) {
      Map rec = (Map) dataSource.get("ROW" + i);
      columnKeys[i] = DataFilter.show(rec, columnLabel);
      for (int j = 0; j < invokeFields.size(); j++) {
        data[j][i] =
            Double.parseDouble(
                rec.get(((Element) invokeFields.get(j)).getAttributeValue("name")).toString());
      }
    }
    for (int i = 0; i < invokeFields.size(); i++) {
      rowKeys[i] = ((Element) invokeFields.get(i)).getAttributeValue("label");
    }

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);

    PlotOrientation plotOrientation =
        chartObject.getAttributeValue("plotOrientation").equalsIgnoreCase("VERTICAL")
            ? PlotOrientation.VERTICAL
            : PlotOrientation.HORIZONTAL;
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            chartObject.getAttributeValue("title"),
            chartObject.getAttributeValue("categoryAxisLabel"),
            chartObject.getAttributeValue("valueAxisLabel"),
            dataset,
            plotOrientation,
            chartObject.getAttribute("showLegend").getBooleanValue(),
            chartObject.getAttribute("showToolTips").getBooleanValue(),
            chartObject.getAttribute("urls").getBooleanValue());

    CategoryPlot C3dplot = (CategoryPlot) chart.getPlot();
    if (chartObject.getAttribute("alpha") != null) {
      C3dplot.setForegroundAlpha(chartObject.getAttribute("alpha").getFloatValue());
    }

    BarRenderer3D barrenderer = (BarRenderer3D) C3dplot.getRenderer();
    barrenderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    barrenderer.setItemLabelsVisible(true);
    barrenderer.setPositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_CENTER));

    int width, height;
    if (chartObject.getAttributeValue("width").equalsIgnoreCase("auto")) {
      width = (50 * dataSource.size()) * invokeFields.size() + 100;
    } else {
      width = Integer.parseInt(chartObject.getAttributeValue("width"));
    }
    if (chartObject.getAttributeValue("height").equalsIgnoreCase("auto")) {
      height = (50 * dataSource.size()) * invokeFields.size() + 100;
    } else {
      height = Integer.parseInt(chartObject.getAttributeValue("height"));
    }

    return ServletUtilities.saveChartAsPNG(chart, width, height, session);
  }