Exemplo n.º 1
0
  /**
   * Creates a sample chart with the given dataset.
   *
   * @param dataset the dataset.
   * @return A sample chart.
   */
  private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart =
        ChartFactory.createMultiplePieChart(
            "Multiple Pie Chart", // chart title
            dataset, // dataset
            TableOrder.BY_ROW,
            true, // include legend
            true,
            true);
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    final JFreeChart subchart = plot.getPieChart();
    final PiePlot p = (PiePlot) subchart.getPlot();
    p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    p.setInteriorGap(0.30);

    return chart;
  }
Exemplo n.º 2
0
  protected void buildChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    chart =
        ChartFactory.createMultiplePieChart(
            "Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN, false, true, false);
    chart.setAntiAlias(true);
    // chartPanel = new ScrollableChartPanel(chart, true);
    chartPanel = buildChartPanel(chart);
    // chartHolder.getViewport().setView(chartPanel);
    setChartPanel(chartPanel);

    JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart();
    PiePlot base = (PiePlot) (baseChart.getPlot());
    base.setIgnoreZeroValues(true);
    base.setLabelOutlinePaint(java.awt.Color.WHITE);
    base.setLabelShadowPaint(java.awt.Color.WHITE);
    base.setMaximumLabelWidth(
        0.25); // allow bigger labels by a bit (this will make the chart smaller)
    base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width
    base.setLabelBackgroundPaint(java.awt.Color.WHITE);
    base.setOutlinePaint(null);
    base.setBackgroundPaint(null);
    base.setShadowPaint(null);
    base.setSimpleLabels(false); // I think they're false anyway

    // change the look of the series title to be smaller
    StandardChartTheme theme = new StandardChartTheme("Hi");
    TextTitle title = new TextTitle("Whatever", theme.getLargeFont());
    title.setPaint(theme.getAxisLabelPaint());
    title.setPosition(RectangleEdge.BOTTOM);
    baseChart.setTitle(title);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
  }
Exemplo n.º 3
0
  /** JFreeChartオブジェクトを作成する */
  private JFreeChart createChartObject(Document doc) {

    Element root = doc.getDocumentElement();
    Element chartInfo = (Element) root.getElementsByTagName("ChartInfo").item(0);
    String chartTitle =
        chartInfo.getElementsByTagName("Title").item(0).getFirstChild().getNodeValue();
    this.chartType = chartInfo.getElementsByTagName("Type").item(0).getFirstChild().getNodeValue();
    String categoryLabel =
        ((Element) chartInfo.getElementsByTagName("Category").item(0))
            .getElementsByTagName("Label")
            .item(0)
            .getFirstChild()
            .getNodeValue();

    Element firstSeries =
        (Element)
            ((Element) chartInfo.getElementsByTagName("SeriesList").item(0))
                .getElementsByTagName("Series")
                .item(0);
    String firstSeriesLabel =
        firstSeries.getElementsByTagName("Label").item(0).getFirstChild().getNodeValue();

    // データセットのリストを取得
    this.dataSetList = this.getDatasetList(doc);

    // 棒チャート(Series数に関わらない)
    if (this.chartType.equals("VerticalBar")
        || this.chartType.equals("HorizontalBar")
        || this.chartType.equals("VerticalMultiBar")
        || this.chartType.equals("HorizontalMultiBar")) {

      chart =
          ChartFactory.createBarChart(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              getLayoutFromDoc(doc),
              false,
              false,
              false);

    }

    // 3D棒チャート(Series数に関わらない)
    else if (this.chartType.equals("Vertical3D_Bar")
        || this.chartType.equals("Horizontal3D_Bar")
        || this.chartType.equals("VerticalMulti3D_Bar")
        || this.chartType.equals("HorizontalMulti3D_Bar")) {

      chart =
          ChartFactory.createBarChart3D(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              getLayoutFromDoc(doc),
              false,
              false,
              false);
    }

    // 積み上げ棒チャート
    else if ((this.chartType.equals("VerticalStackedBar"))
        || (this.chartType.equals("HorizontalStackedBar"))) {

      chart =
          ChartFactory.createStackedBarChart(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              getLayoutFromDoc(doc),
              false,
              false,
              false);

    }

    // 3D積み上げ棒チャート
    else if ((this.chartType.equals("VerticalStacked3D_Bar"))
        || (this.chartType.equals("HorizontalStacked3D_Bar"))) {

      chart =
          ChartFactory.createStackedBarChart3D(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              getLayoutFromDoc(doc),
              false,
              false,
              false);

    }

    // 折れ線チャート(Series数に関わらない)
    else if ((this.chartType.equals("Line")) || (this.chartType.equals("MultiLine"))) {

      chart =
          ChartFactory.createLineChart(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              PlotOrientation.VERTICAL,
              false,
              false,
              false);

    }

    // 面チャート(Series数に関わらない)
    else if ((this.chartType.equals("Area")) || (this.chartType.equals("MultiArea"))) {

      chart =
          ChartFactory.createAreaChart(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              PlotOrientation.VERTICAL,
              false,
              false,
              false);

    }

    // 積み上げ面チャート
    else if (this.chartType.equals("StackedArea")) {

      chart =
          ChartFactory.createStackedAreaChart(
              chartTitle,
              categoryLabel,
              firstSeriesLabel,
              (CategoryDataset) this.dataSetList.get(0),
              PlotOrientation.VERTICAL,
              false,
              false,
              false);

    }

    // 円チャート(Series数に関わらない)
    else if (this.chartType.equals("Pie")) {

      chart =
          ChartFactory.createPieChart(
              chartTitle, (PieDataset) this.dataSetList.get(0), false, false, false);

    }

    // 3D円チャート(Series数に関わらない)
    else if (this.chartType.equals("Pie_3D")) {

      chart =
          ChartFactory.createPieChart3D(
              chartTitle, (PieDataset) this.dataSetList.get(0), false, false, false);

    }

    // 複数円チャート(Series数が2以上)
    else if (this.chartType.equals("MultiPie")) {

      // 複数円チャート
      chart =
          ChartFactory.createMultiplePieChart(
              chartTitle,
              (CategoryDataset) this.dataSetList.get(0),
              TableOrder.BY_ROW,
              false,
              false,
              false);
    }

    return chart;
  }