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);
  }
  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);
  }
 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;
 }