public String generatePieChart(
      String hitOrdNum, HttpSession session, PrintWriter pw, String courseId, int studentId) {
    /* int groupId=0;
                if (groupName.equals("All")){
                    groupId=0;
                }else{
                     groupId = studStatisticBean.getGroupIdByName(groupName);
    }*/
    String filename = null;
    try {
      //  Retrieve list of WebHits
      StudentsConceptChartDataSet whDataSet =
          new StudentsConceptChartDataSet(studStatisticBean, courseId, studentId);
      ArrayList list = whDataSet.getDataBySection(hitOrdNum);

      //  Throw a custom NoDataException if there is no data
      if (list.size() == 0) {
        System.out.println("No data has been found");
        throw new NoDataException();
      }

      //  Create and populate a PieDataSet
      DefaultPieDataset data = new DefaultPieDataset();
      Iterator iter = list.listIterator();
      while (iter.hasNext()) {
        StudentsConceptHit wh = (StudentsConceptHit) iter.next();
        data.setValue(wh.getSection(), wh.getHitDegree());
      }

      //  Create the chart object
      PiePlot plot = new PiePlot(data);
      plot.setInsets(new Insets(0, 5, 5, 5));
      plot.setURLGenerator(new StandardPieURLGenerator("xy_chart.jsp", "section"));
      plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
      JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
      chart.setBackgroundPaint(java.awt.Color.white);

      //  Write the chart image to the temporary directory
      ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
      filename = ServletUtilities.saveChartAsPNG(chart, 600, 400, info, session);

      //  Write the image map to the PrintWriter
      ChartUtilities.writeImageMap(pw, filename, info);
      pw.flush();

    } catch (NoDataException e) {
      System.out.println(e.toString());
      filename = "public_nodata_500x300.png";
    } catch (Exception e) {
      System.out.println("Exception - " + e.toString());
      e.printStackTrace(System.out);
      filename = "public_error_500x300.png";
    }

    return filename;
  }
Example #2
0
  /** 円チャート用ツールチップ設定メソッド */
  public void setToolTipForPie(Document doc) {

    Element root = doc.getDocumentElement();
    Element chartInfo = (Element) root.getElementsByTagName("ChartInfo").item(0);
    String hasToolTip =
        chartInfo.getElementsByTagName("hasToolTip").item(0).getFirstChild().getNodeValue();

    // ツールチップ有り
    if ("1".equals(hasToolTip)) {
      PiePlot piePlot = this.getPiePlot();
      piePlot.setToolTipGenerator(new StandardPieItemLabelGenerator());
    }

    // ツールチップ無し
    else {
      // 何もしない(ツールチップ表示しない)
    }
  }
Example #3
0
  /**
   * Creates a chart containing multiple pie charts, from a TableDataset.
   *
   * @param title the chart title.
   * @param data the dataset for the chart.
   * @param extractType <code>PER_ROW</code> or <code>PER_COLUMN</code> (defined in {@link
   *     PiePlot}).
   * @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 pie chart.
   */
  public static JFreeChart createPieChart(
      String title,
      java.awt.Font titleFont,
      CategoryDataset data,
      TableOrder order,
      boolean legend,
      boolean tooltips,
      boolean urls,
      PieURLGenerator urlGenerator) {

    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setInsets(new Insets(0, 5, 5, 5));
    pp.setBackgroundPaint(null);
    // no outline around each piechart
    pp.setOutlineStroke(null);
    // plot.setOutlineStroke(null);
    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
      tooltipGenerator = new StandardPieToolTipGenerator();
    }

    // PieURLGenerator urlGenerator = null;
    if (!urls) {
      urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);

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

    return chart;
  }