Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
  }