protected void configurePlot(Plot plot, JRChartPlot jrPlot) {

    super.configurePlot(plot, jrPlot);

    if (plot instanceof CategoryPlot) {
      CategoryPlot categoryPlot = (CategoryPlot) plot;
      CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
      CategoryDataset categoryDataset = categoryPlot.getDataset();
      if (categoryDataset != null) {
        for (int i = 0; i < categoryDataset.getRowCount(); i++) {
          categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }
      }
      categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
      categoryPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
      categoryPlot.setDomainGridlinesVisible(false);
      categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    } else if (plot instanceof XYPlot) {
      XYPlot xyPlot = (XYPlot) plot;
      XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
      XYDataset xyDataset = xyPlot.getDataset();
      if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
          xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
        }
      }
      xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
      xyPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
      xyPlot.setDomainGridlinesVisible(false);
      xyPlot.setRangeZeroBaselineVisible(true);
    }
  }
コード例 #2
0
  private void btnPictorialViewActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnPictorialViewActionPerformed
    // TODO add your handling code here:
    DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();

    for (Product product : supplier.getProductCatalog().getProductCatalog()) {
      categoryDataset.setValue(product.getSoldQuantity(), "Units", product.getProdName());
    }
    JFreeChart freeChart =
        ChartFactory.createBarChart(
            "Sales Report",
            "Product",
            "Units",
            categoryDataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);

    CategoryPlot categoryPlot = freeChart.getCategoryPlot();
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    ChartFrame cf = new ChartFrame("Sales Report", freeChart);
    cf.setVisible(true);
    cf.setSize(450, 300);
  } // GEN-LAST:event_btnPictorialViewActionPerformed
コード例 #3
0
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createLineChart(
           "Statistical Line Chart Demo 1",
           "Type",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   CategoryAxis categoryaxis = categoryplot.getDomainAxis();
   categoryaxis.setUpperMargin(0.0D);
   categoryaxis.setLowerMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setAutoRangeIncludesZero(true);
   StatisticalLineAndShapeRenderer statisticallineandshaperenderer =
       new StatisticalLineAndShapeRenderer(true, false);
   statisticallineandshaperenderer.setUseSeriesOffset(true);
   categoryplot.setRenderer(statisticallineandshaperenderer);
   return jfreechart;
 }
コード例 #4
0
  public BoxplotChart(String title, String xAxisTitle, String yAxisTitle) {
    super();
    dataset = new DefaultBoxAndWhiskerCategoryDataset();

    CategoryAxis xAxis = new CategoryAxis("Type");
    NumberAxis yAxis = new NumberAxis("Value");
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    chart = new JFreeChart(title, plot);

    Font font = new Font("Helvetica", Font.BOLD, 12);
    xAxis.setLabelFont(font);
    xAxis.setLabel(xAxisTitle);
    yAxis.setLabelFont(font);
    yAxis.setLabel(yAxisTitle);

    // Making it pretty
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    chart.setBackgroundPaint(Color.white);
    chart.setTextAntiAlias(true);
    yAxis.setAutoRange(true);
    colorGenerator = new ColorGenerator();
    datasetIndex = 0;

    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setBorder(1, 1, 1, 1);
  }
コード例 #5
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createchart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 1", // chart
            // title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    //
    // > http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    // renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
コード例 #6
0
    protected void configurePlot(CategoryPlot plot) {
      plot.setBackgroundPaint(Color.WHITE);
      plot.setOutlinePaint(null);
      plot.setRangeGridlinesVisible(true);
      plot.setRangeGridlinePaint(Color.black);

      configureRenderer((LineAndShapeRenderer) plot.getRenderer());
      configureDomainAxis(plot);
    }
コード例 #7
0
ファイル: AbstractBarChart.java プロジェクト: Depter/JRLib
  @Override
  protected void formatPlot(Plot plot) {
    CategoryPlot cPlot = (CategoryPlot) plot;
    cPlot.setBackgroundPaint(format.getBackgroundColor());
    cPlot.setRangeGridlinePaint(format.getGridColor());
    cPlot.setDomainGridlinePaint(format.getGridColor());

    formatRenderer((BarRenderer) cPlot.getRenderer());
    setRange();
  }
コード例 #8
0
ファイル: LineChart.java プロジェクト: RainerJava/inventory
  private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart =
        ChartFactory.createLineChart(
            "Daily Stock Report", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesStroke(
        0,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {10.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        1,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {6.0f, 6.0f},
            0.0f));
    renderer.setSeriesStroke(
        2,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {2.0f, 6.0f},
            0.0f));
    return chart;
  }
コード例 #9
0
ファイル: LineChartGen.java プロジェクト: richiewang/caipiao
  public JFreeChart createChart(int size) {
    CategoryDataset paramCategoryDataset = createDataset(size);
    // 创建主题样式
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    // 设置标题字体
    standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
    // 设置图例的字体
    standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 12));
    // 设置轴向的字体
    standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 12));
    // 应用主题样式
    ChartFactory.setChartTheme(standardChartTheme);
    JFreeChart localJFreeChart =
        ChartFactory.createLineChart(
            title, "期号", yTitle, paramCategoryDataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
    //		SymbolAxis localSymbolAxis = new SymbolAxis("个数", new String[] {
    //				"0", "1", "2", "3", "4", "5", "6" });
    //		localCategoryPlot.setRangeAxis(localSymbolAxis);
    ChartUtilities.applyCurrentTheme(localJFreeChart);
    LineAndShapeRenderer xyitem = (LineAndShapeRenderer) localCategoryPlot.getRenderer();
    CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot();
    // 设置网格背景颜色
    plot.setBackgroundPaint(Color.white);
    // 设置网格竖线颜色
    plot.setDomainGridlinePaint(Color.black);
    // 设置网格横线颜色
    plot.setRangeGridlinePaint(Color.black);
    // 设置曲线图与xy轴的距离
    plot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 0D));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    if ("和值".equals(type)) {
      rangeAxis.setLowerBound(70);
      rangeAxis.setTickUnit(new NumberTickUnit(10));
    } else {
      rangeAxis.setLowerBound(0);
      rangeAxis.setTickUnit(new NumberTickUnit(1));
    }
    //		rangeAxis.setUpperMargin(0.20);
    // 设置曲线显示各数据点的值
    xyitem.setBaseItemLabelsVisible(true);
    xyitem.setBasePositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    xyitem.setSeriesStroke(0, new BasicStroke(1.5F));
    xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
    xyitem.setSeriesShapesVisible(0, true);
    plot.setRenderer(xyitem);
    return localJFreeChart;
  }
コード例 #10
0
  @Override
  protected JFreeChart createGraph() {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    rangeAxis.setAutoRange(true);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
  }
コード例 #11
0
ファイル: StackedBarChart.java プロジェクト: CaoAo/BeehiveZ
  // Pie Chart
  // //////////////////////////////////////////////////////////////////////////////
  protected JScrollPane getGraphPanel() {
    DefaultCategoryDataset dataset;
    if (absPerformance instanceof AbstractPerformance2D) {
      dataset = getDefaultCategoryDataset((AbstractPerformance2D) absPerformance);
    } else {
      dataset = getDefaultCategoryDataset(absPerformance);
    }

    PlotOrientation order = PlotOrientation.VERTICAL;
    if (orientationSort.getValue().equals("Horizontal")) {
      order = PlotOrientation.HORIZONTAL;
    }

    String strCategory = absPerformance.getItemName();
    if (absPerformance instanceof AbstractPerformance2D) {
      if (isItemA) {
        strCategory = ((AbstractPerformance2D) absPerformance).getSecondItemName();
      } else {
        strCategory = ((AbstractPerformance2D) absPerformance).getItemName();
      }
    }
    if (dimSort.getValue().equals("2D")) {
      chart =
          ChartFactory.createStackedBarChart(
              null, strCategory, "time", dataset, order, bLegend, true, false);
    } else if (dimSort.getValue().equals("3D")) {
      chart =
          ChartFactory.createStackedBarChart3D(
              null, strCategory, "time", dataset, order, bLegend, true, false);
    }

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    chartPanel = new ChartPanel(chart, false);
    scrollPane = new JScrollPane(chartPanel);
    return scrollPane;
  }
コード例 #12
0
  public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report =
        ChartFactory.createStackedBarChart(
            this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(),
            categorydataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
        || datasetStrategy instanceof MultiCloverBarChartStrategy) {
      numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
      numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setItemLabelFont(
        StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height =
        (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT
            + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
      super.setHeight(height);
    } else {
      super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
      stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }
  }
コード例 #13
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "", // chart
            // title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
コード例 #14
0
ファイル: GanttPlotter.java プロジェクト: preesm/preesm-apps
  /**
   * Creates a chart.
   *
   * @param dataset a dataset.
   * @return A chart.
   */
  private JFreeChart createChart(Gantt gantt, IntervalCategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createGanttChart(
            "Solution Gantt", // title
            "Operators", // x-axis label
            "Time", // y-axis label
            null, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    Paint p = getBackgroundColorGradient();
    chart.setBackgroundPaint(p);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    DateAxis xaxis = (DateAxis) plot.getRangeAxis();
    xaxis.setDateFormatOverride(new VertexDateFormat());
    xaxis.setPositiveArrowVisible(true);

    DefaultDrawingSupplier d = new DefaultDrawingSupplier();

    plot.setDrawingSupplier(d);
    GanttRenderer ren = new MyGanttRenderer();

    for (GanttElement element : gantt.getElementSet()) {
      ((MyGanttRenderer) ren).addColor(element.getTitle(), element.getColor());
    }

    ren.setSeriesItemLabelsVisible(0, false);
    ren.setSeriesVisibleInLegend(0, false);
    ren.setSeriesItemLabelGenerator(0, new IntervalCategoryItemLabelGenerator());
    ren.setSeriesToolTipGenerator(0, new MapperGanttToolTipGenerator());

    ren.setAutoPopulateSeriesShape(false);

    plot.setRenderer(ren);

    plot.setDataset(dataset);
    return chart;
  }
コード例 #15
0
 private static JFreeChart createChart(CategoryDataset categorydataset, String title) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart(
           title, "分类:区域", "短信数", categorydataset, PlotOrientation.HORIZONTAL, true, true, false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
   StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
   stackedbarrenderer.setDrawBarOutline(false);
   stackedbarrenderer.setMaximumBarWidth(0.1);
   stackedbarrenderer.setItemLabelsVisible(true);
   return jfreechart;
 }
  protected JFreeChart createGanttChart() throws JRException {

    JFreeChart jfreeChart = super.createGanttChart();
    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    categoryPlot.setDomainGridlinesVisible(true);
    categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);
    categoryPlot.setDomainGridlineStroke(
        new BasicStroke(
            0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 50, new float[] {1}, 0));

    categoryPlot.setDomainGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);

    categoryPlot.setRangeGridlinesVisible(true);
    categoryPlot.setRangeGridlineStroke(
        new BasicStroke(
            0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 50, new float[] {1}, 0));

    categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
    //		JRBarPlot barPlot = (BarPlot)categoryPlot;
    //		categoryPlot.getDomainAxis().setTickLabelsVisible(
    //				categoryPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels().
    //				true
    //				);
    CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
    categoryRenderer.setBaseItemLabelsVisible(true);
    BarRenderer barRenderer = (BarRenderer) categoryRenderer;
    List seriesPaints =
        (List) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS);
    barRenderer.setSeriesPaint(0, (Paint) seriesPaints.get(3));
    barRenderer.setSeriesPaint(1, (Paint) seriesPaints.get(0));
    CategoryDataset categoryDataset = categoryPlot.getDataset();
    if (categoryDataset != null) {
      for (int i = 0; i < categoryDataset.getRowCount(); i++) {
        barRenderer.setSeriesItemLabelFont(i, categoryPlot.getDomainAxis().getTickLabelFont());
        barRenderer.setSeriesItemLabelsVisible(i, true);
        //			barRenderer.setSeriesPaint(i, GRADIENT_PAINTS[i]);
        //			CategoryMarker categoryMarker = new
        // CategoryMarker(categoryDataset.getColumnKey(i),MARKER_COLOR, new BasicStroke(1f));
        //			categoryMarker.setAlpha(0.5f);
        //			categoryPlot.addDomainMarker(categoryMarker, Layer.BACKGROUND);
      }
    }
    categoryPlot.setOutlinePaint(Color.DARK_GRAY);
    categoryPlot.setOutlineStroke(new BasicStroke(1.5f));
    categoryPlot.setOutlineVisible(true);
    return jfreeChart;
  }
コード例 #17
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "SubCategoryAxis Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    SubCategoryAxis axis = new SubCategoryAxis(null);
    axis.addSubCategory("S1");
    axis.addSubCategory("S2");
    axis.addSubCategory("S3");
    plot.setDomainAxis(axis);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartUtilities.applyCurrentTheme(chart);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    return chart;
  }
コード例 #18
0
ファイル: First.java プロジェクト: RUB3XT0R/java_projects
  public static void createChart() {
    // criação do gráfico
    JFreeChart chart =
        ChartFactory.createLineChart(
            "Gráfico da Função: " + funcao, // titulo do gráfico
            "Resultados", // eixoy
            "Valores de Entrada", // eixox
            dataset, // base de dados
            PlotOrientation.VERTICAL,
            false, // legenda
            true, // dica, popup
            false // urls
            );
    // personalizando o gráfico

    TextTitle source =
        new TextTitle(
            "Atenção! Dependo do número de valores, pode ser que não apareça os mesmos no eixo horizontal.");
    source.setFont(new Font("SansSerif", Font.PLAIN, 10));
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    source.setBackgroundPaint(Color.WHITE);

    chart.addSubtitle(source);
    chart.setBackgroundPaint(Color.GRAY);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.BLACK);

    // desenha os pontos
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setLegendTextPaint(1, Color.WHITE);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame frame = new ChartFrame("Gráfico - Calculadora Função Atividade 2", chart);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
コード例 #19
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            "Bar Chart Demo 8", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    // disable bar outlines...
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
コード例 #20
0
  private PanelTopPadecimientos() {
    setBackground(Color.WHITE);
    setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    estadisticaModelo = ModeloEstadistica.getInstancia((Manejador.getInstancia(false, false)));

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    DefaultCategoryDataset datasetPadecimiento = new DefaultCategoryDataset();
    ArrayList<Estadistica> estadisticaPadecimiento =
        (ArrayList<Estadistica>) estadisticaModelo.getEstadisticaPadecimiento();

    for (Estadistica estadist : estadisticaPadecimiento) {
      System.out.println(estadist.getTotal() + "\t" + estadist.getMedicoId());

      long val;
      val = (long) estadist.getTotal();
      String val2 = "";
      val2 += estadist.getMedicoId();

      dataset.setValue(val, "Padecimiento", val2);
    }

    JFreeChart chartPadecimiento =
        ChartFactory.createBarChart(
            "Top 10 padecimientos más frecuentados",
            "",
            "Padecimientos",
            dataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);
    chartPadecimiento.setBackgroundPaint(Color.white);
    chartPadecimiento.getTitle().setPaint(Color.blue);
    CategoryPlot pa = chartPadecimiento.getCategoryPlot();
    pa.setRangeGridlinePaint(Color.red);
    setLayout(null);
    ChartPanel panelPadecimiento = new ChartPanel(chartPadecimiento);
    panelPadecimiento.setBounds(47, 41, 837, 551);
    panelPadecimiento.setBackground(SystemColor.control);
    add(panelPadecimiento);
  }
コード例 #21
0
ファイル: LoadStatistics.java プロジェクト: atcarmo/jenkins
  /** Creates a trend chart. */
  public JFreeChart createChart(CategoryDataset ds) {
    final JFreeChart chart =
        ChartFactory.createLineChart(
            null, // chart title
            null, // unused
            null, // range axis label
            ds, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(3));
    configureRenderer(renderer);

    final CategoryAxis domainAxis = new NoOverlapCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
  }
コード例 #22
0
  /* (non-Javadoc)
   * @see com.alpine.datamining.api.impl.visual.ImageVisualizationType#generateOutPut(com.alpine.datamining.api.AnalyticOutPut)
   */
  @Override
  public VisualizationOutPut generateOutPut(AnalyticOutPut analyzerOutPut) {
    AnalyzerOutPutBoxWhisker obj = null;
    if (analyzerOutPut instanceof AnalyzerOutPutBoxWhisker) {
      obj = (AnalyzerOutPutBoxWhisker) analyzerOutPut;
    }
    List<BoxAndWhiskerItem> list = obj.getItemList();
    BoxAndWhiskerDataset dataset = new BoxAndWhiskerDataset();
    String variableName = null;
    String seriesName = null;
    String typeName = null;

    double[] maxArray = new double[list.size()];
    double[] minArray = new double[list.size()];
    // find max and min
    for (int i = 0; i < list.size(); i++) {
      maxArray[i] = list.get(i).getMax().doubleValue();
      minArray[i] = list.get(i).getMin().doubleValue();
    }

    Arrays.sort(maxArray);
    Arrays.sort(minArray);

    double max = maxArray[maxArray.length - 1];
    double min = minArray[0];

    long n = AlpineMath.adjustUnits(min, max);

    for (BoxAndWhiskerItem item : list) {
      dataset.add(
          item.getMean().doubleValue() / n,
          item.getMedian().doubleValue() / n,
          item.getQ1().doubleValue() / n,
          item.getQ3().doubleValue() / n,
          item.getMin().doubleValue() / n,
          item.getMax().doubleValue() / n,
          0,
          0,
          null,
          item.getSeries(),
          item.getType());
    }
    if (list != null && list.size() > 0) {
      variableName = list.get(0).getVariableName();
      if (variableName == null) variableName = "";
      seriesName = list.get(0).getSeriesName();
      if (seriesName == null) seriesName = "";
      typeName = list.get(0).getTypeName();
      if (typeName == null) typeName = "";
    }

    String yLabel =
        n == 1
            ? variableName
            : variableName
                + " "
                + VisualLanguagePack.getMessage(VisualLanguagePack.UNITS, locale)
                + " ("
                + com.alpine.datamining.api.utility.AlpineMath.powExpression(n)
                + ")";

    final CategoryAxis xAxis = new CategoryAxis(typeName);
    xAxis.setLabelFont(VisualResource.getChartFont());
    final NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setLabelFont(VisualResource.getChartFont());
    yAxis.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    if (list != null && list.size() < 5) {
      renderer.setMaximumBarWidth(0.2);
      renderer.setItemMargin(0.7);
    }

    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    DrawingSupplier supplier =
        new DefaultDrawingSupplier(
            createPaintArray(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    plot.setDrawingSupplier(supplier);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final JFreeChart chart = new JFreeChart(" ", VisualResource.getChartFont(), plot, true);
    chart.removeLegend();
    if (!seriesName.trim().equals("")) {
      final TextTitle subtitle = new TextTitle(seriesName, VisualResource.getChartFont());
      chart.addSubtitle(subtitle);
      chart.addLegend(new LegendTitle(plot));
      chart.getLegend().setItemFont(VisualResource.getChartFont());
    }
    JFreeChartImageVisualizationOutPut output = new JFreeChartImageVisualizationOutPut(chart);
    output.setName(analyzerOutPut.getAnalyticNode().getName());
    return output;
  }
コード例 #23
0
  private void createGraphs() {
    long time = System.currentTimeMillis();
    System.out.println("Creating graphs...");
    final String[] rowKeys = {"to BB", "to Pot", "to Stack", "to Previous"};

    for (int game = 0; game < distributions.length; game++) {
      for (int position = 0; position < distributions[game].length; position++) {
        for (int stage = 0; stage < distributions[game][position].length; stage++) {
          for (int action = 1; action < distributions[game][position][stage].length; action++) {
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            for (int tox = 0; tox < distributions[game][position][stage][action].length; tox++) {
              for (int group = 0;
                  group < distributions[game][position][stage][action][tox].length;
                  group++) {
                //								String colKey = "";
                //								colKey = (group % 5 == 0) ?
                // group+"/"+(double)group/10+"/"+(double)group/2+"/"+(double)group/2 :
                // String.valueOf(group);
                dataset.addValue(
                    round(
                        (double) distributions[game][position][stage][action][tox][group]
                            / sumActions[game][position][stage][action]),
                    rowKeys[tox],
                    (group == 100) ? ">=100" : String.valueOf(group));
              }
            }
            String name = "";
            if (game == HU) name += "HU_";
            else if (game == SH) name += "SH_";
            else if (game == FR) name += "FR_";
            name += position + "_";
            if (stage == PREFLOP) name += "Preflop_";
            else if (stage == FLOP) name += "Flop_";
            else if (stage == TURN) name += "Turn_";
            else if (stage == RIVER) name += "River_";
            if (action == CALL) name += "CALL";
            else if (action == BET) name += "BET";
            else if (action == RAISE) name += "RAISE";
            else if (action == _3BET) name += "3BET";
            else if (action == _4BET) name += "4BET";
            else if (action == _5BET) name += "5BET";

            JFreeChart chart =
                ChartFactory.createLineChart(
                    name,
                    "bucket of amount",
                    "% of actions",
                    dataset,
                    PlotOrientation.VERTICAL,
                    true,
                    false,
                    false);
            // set the background color for the chart...
            chart.setBackgroundPaint(Color.white);

            // get a reference to the plot for further customisation...
            CategoryPlot plot = chart.getCategoryPlot();
            plot.setBackgroundPaint(Color.white);
            plot.setDomainGridlinePaint(Color.white);
            plot.setRangeGridlinePaint(Color.lightGray);

            // set the range axis to display integers only...
            //			        	CategoryAxis rangeAxis = plot.getDomainAxis();
            //			        	rangeAxis.setCategoryLabelPositionOffset(0);

            // disable bar outlines...
            //						BarRenderer renderer = (BarRenderer) plot.getRenderer();
            //						renderer.setDrawBarOutline(false);
            //						renderer.setShadowVisible(false);
            try {
              ChartUtilities.saveChartAsJPEG(
                  new File(folder + "graphs\\" + name + ".jpg"), chart, 1500, 500);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
      }
    }
    System.out.println("Creating Graphs finished in " + (System.currentTimeMillis() - time) + "ms");
  }
コード例 #24
0
  private BufferedImage generarGraficoBarrasDistribucionResultados(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      double[] valores,
      String[] funciones,
      boolean porcentaje,
      boolean leyenda,
      int intervaloAprobacion,
      int anchoImagen,
      int altoImagen) {
    if (valores.length != funciones.length) {
      return null;
    }
    DefaultCategoryDataset pieDataset = new DefaultCategoryDataset();
    for (int i = 0; i < valores.length; i++) {
      pieDataset.addValue(valores[i], "Serie 1", funciones[i]);
    }
    JFreeChart chart =
        ChartFactory.createBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            pieDataset,
            PlotOrientation.VERTICAL,
            leyenda,
            true,
            false);
    chart.setBackgroundPaint(null);
    chart.setBorderVisible(false);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    final AprobadoDesaprobadoBarRenderer renderer = new AprobadoDesaprobadoBarRenderer();
    renderer.setIntervaloAprobacion(intervaloAprobacion);
    plot.setRenderer(renderer);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    this.lastChart = chart;

    // Generamos una imagen
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
コード例 #25
0
  /** Comienzo de mètodos básicos. */
  private BufferedImage generarGraficoBarrasApiladas(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      PlotOrientation orientacion,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        dataset.addValue(serie.valores[i], serie.funciones[i], serie.nombre);
      }
    }
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            dataset,
            orientacion,
            leyenda,
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap(series.get(0).nombre);
    for (Serie serie : series) {
      map.mapKeyToGroup(serie.nombre, serie.nombre);
    }
    renderer.setSeriesToGroupMap(map);
    renderer.setDrawBarOutline(false);
    renderer.setRenderAsPercentages(porcentaje);
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          Color color = generarColorAleatorio(Color.orange);
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

    renderer.setGradientPaintTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    domainAxis.setCategoryMargin(0.05);

    plot.setRenderer(renderer);

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
コード例 #26
0
  private BufferedImage generarGraficoBarras(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        barDataset.addValue(serie.valores[i], serie.nombre, serie.funciones[i]);
      }
    }

    JFreeChart chart =
        ChartFactory.createBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            barDataset,
            PlotOrientation.VERTICAL,
            leyenda,
            true,
            false);
    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        Color color = generarColorAleatorio(Color.orange);
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }
コード例 #27
0
  @Override
  public JFreeChart createChart(int nbr) {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    // DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();   bias

    for (Tuple<String, double[]> tuple : this.mreDblFileList) {
      for (int h = 0; h < 24; h++) {
        dataset0.addValue(tuple.getSecond()[h], tuple.getFirst(), Integer.toString(h + 1));
      }
    }

    this.chart_ =
        ChartFactory.createLineChart(
            "",
            "Hour",
            "Mean rel error [%]",
            dataset0,
            PlotOrientation.VERTICAL,
            true, // legend?
            true, // tooltips?
            false // URLs?
            );

    CategoryPlot plot = this.chart_.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    plot.setRenderer(0, renderer);

    Color transparent = new Color(0, 0, 255, 0);
    this.chart_.setBackgroundPaint(
        transparent); // pink : Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93)
    plot.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93));
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlinesVisible(true);

    final CategoryAxis axisX = new CategoryAxis("Hour");
    axisX.setTickLabelFont(new Font("SansSerif", Font.BOLD, 15));
    plot.setDomainAxis(axisX);

    // final ValueAxis axis2 = new NumberAxis("Mean abs bias [agent/h]");
    // plot.setRangeAxis(1, axis2);

    final ValueAxis axisY = plot.getRangeAxis(0);
    axisY.setRange(0.0, 100.0);
    axisY.setTickLabelFont(new Font("SansSerif", Font.BOLD, 21));

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    this.chart_.getLegend().setItemFont(new Font("SansSerif", Font.BOLD, 17));
    this.chart_.getLegend().setVisible(false);

    return this.chart_;
  }
コード例 #28
0
  public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart =
        ChartFactory.createBarChart3D(
            "Загрузка данных", // chart title
            "Дата", // domain axis label
            "Значение (кб.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    //		#44639C;

    TextTitle title = new TextTitle("Динамика загрузки данных", labelFont);
    //		Paint paint = title.getPaint();
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // final IntervalMarker target = new IntervalMarker(2000000, 3000000);
    // target.setLabel("Ожидаемый диапазон");
    // target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    // target.setLabelAnchor(RectangleAnchor.LEFT);
    // target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    // target.setPaint(new Color(222, 222, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickLabelFont(labelFont);

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    final GradientPaint gp1 =
        new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)
        // CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
        );
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
コード例 #29
0
  @Override
  protected void setChart() {
    SeriesManager<Integer, Integer> sf = new SeriesManager<Integer, Integer>(intermediateData);
    List<DataSeries<Integer, Integer>> seriesList = sf.getSeries();

    // Adds the 'All Spectra' series at the end in the local variable 'seriesList'
    // **NOTE** The intermediateData is NOT modified
    seriesList.add(getAllSpectraSeries(seriesList));

    List<Color> seriesColor = new ArrayList<Color>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (DataSeries<Integer, Integer> series : seriesList) {
      DataSeriesType seriesType = series.getType();
      if (!visibleTypes.contains(seriesType)) continue;

      String serieKey = series.getIdentifier();
      List<SeriesPair<Integer, Integer>> values =
          series.getSeriesValues(Integer.class, Integer.class);

      Map<String, Integer> map = new HashMap<String, Integer>();
      // The map is filled with the intermediate data values
      int greaterThanTopValue = 0;
      for (SeriesPair<Integer, Integer> value : values) {
        int xValue = value.getX();
        int yValue = value.getY();
        if (xValue > TOP_VALUE) {
          greaterThanTopValue += yValue;
        } else {
          map.put("" + xValue, yValue);
        }
      }

      // Finally the JFreeChart data object is created and filled with the processed data
      // DefaultKeyedValues data = new DefaultKeyedValues();
      for (int i = 1; i <= TOP_VALUE; i++) {
        String category = "" + i;
        int value = map.containsKey(category) ? map.get(category) : 0;
        dataset.addValue(value, serieKey, category);
      }
      dataset.addValue(greaterThanTopValue, serieKey, GT_TOP_VALUE_KEY);
      seriesColor.add(seriesType.getColor());
    }

    chart =
        ChartFactory.createBarChart(
            getChartTitle(), // chart title
            "Precursor Ion Charge", // x axis label
            "Frequency", // y axis label
            dataset, // chartData
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );
    chart.addSubtitle(new TextTitle());

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new NumberLegendGenerator());
    for (int i = 0; i < dataset.getRowCount(); i++) {
      renderer.setSeriesItemLabelsVisible(i, Boolean.TRUE);
      renderer.setSeriesPaint(i, seriesColor.get(i));
    }

    plot.getRangeAxis().setUpperMargin(CHART_UPPER_MARGIN);
    plot.setBackgroundAlpha(0f);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.blue);

    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0);
  }
コード例 #30
0
ファイル: JFreeData.java プロジェクト: subaochen/seam
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            "Public Opinion : Torture of Prisoners",
            "Country", // domain axis label
            "%", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
            );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setMargin(2.0, 0.0, 0.0, 0.0);

    TextTitle tt =
        new TextTitle(
            "Source: http://news.bbc.co.uk/1/hi/world/6063386.stm",
            new Font("Dialog", Font.PLAIN, 11));
    tt.setPosition(RectangleEdge.BOTTOM);
    tt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    tt.setMargin(0.0, 0.0, 4.0, 4.0);
    chart.addSubtitle(tt);

    TextTitle t =
        new TextTitle(
            "(*) Across 27,000 respondents in 25 countries", new Font("Dialog", Font.PLAIN, 11));
    t.setPosition(RectangleEdge.BOTTOM);
    t.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    t.setMargin(4.0, 0.0, 2.0, 4.0);
    chart.addSubtitle(t);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LegendItemCollection items = new LegendItemCollection();
    items.add(
        new LegendItem(
            "Against all torture",
            null,
            null,
            null,
            new Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0),
            Color.green));
    items.add(
        new LegendItem(
            "Some degree permissible",
            null,
            null,
            null,
            new Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0),
            Color.red));
    plot.setFixedLegendItems(items);
    plot.setInsets(new RectangleInsets(5, 5, 5, 20));
    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.0);

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    Paint gp1 = new Color(0, 0, 0, 0);
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    // renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(0, Color.green);
    renderer.setSeriesPaint(1, gp1);
    // renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(2, Color.red);

    return chart;
  }