/**
   * Draws a grid line against the domain axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the Java2D value at which the grid line should be drawn.
   */
  public void drawDomainGridline(
      Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {

    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
      double y0 = value;
      double y1 = value - getYOffset();
      double x0 = dataArea.getMinX();
      double x1 = x0 + getXOffset();
      double x2 = dataArea.getMaxX();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x2, y1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      double x0 = value;
      double x1 = value + getXOffset();
      double y0 = dataArea.getMaxY();
      double y1 = y0 - getYOffset();
      double y2 = dataArea.getMinY();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x1, y2);
    }
    Paint paint = plot.getDomainGridlinePaint();
    Stroke stroke = plot.getDomainGridlineStroke();
    g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
    g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
    g2.draw(line1);
    g2.draw(line2);
  }
 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;
 }
  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);
  }
Example #4
0
  public static void main(String[] args) throws IOException {
    JFreeChart chart =
        ChartFactory.createBarChart3D(
            "图书销量统计图",
            "图书", // 目录轴的显示标签
            "销量", // 数值轴的显示标签
            getDataSet(),
            PlotOrientation.VERTICAL, // 设置图表方向
            false,
            false,
            false);

    // 设置标题
    chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));
    // 设置图表部分
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryAxis categoryAxis = plot.getDomainAxis(); // 取得横轴
    categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22)); // 设置横轴显示标签的字体
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 分类标签以45度倾斜
    categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 18)); // 分类标签字体

    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); // 取得纵轴
    numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 42)); // 设置纵轴显示标签字体
    FileOutputStream fos = null;
    fos = new FileOutputStream("book1.jpg");
    ChartUtilities.writeChartAsJPEG(fos, 1, chart, 800, 600, null);

    fos.close();
  }
  /**
   * Draws a grid line against the range axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param axis the value axis.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the value at which the grid line should be drawn.
   */
  public void drawRangeGridline(
      Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
      return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
      line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
    } else if (orientation == PlotOrientation.VERTICAL) {
      line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
    }

    Paint paint = plot.getRangeGridlinePaint();
    if (paint == null) {
      paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getRangeGridlineStroke();
    if (stroke == null) {
      stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);
  }
  /**
   * Returns a legend item for a series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return The legend item.
   */
  public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot p = getPlot();
    if (p == null) {
      return null;
    }

    CategoryDataset dataset;
    dataset = p.getDataset(datasetIndex);
    String label = this.legendItemLabelGenerator.generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (this.legendItemToolTipGenerator != null) {
      toolTipText = this.legendItemToolTipGenerator.generateLabel(dataset, series);
    }
    String urlText = null;
    if (this.legendItemURLGenerator != null) {
      urlText = this.legendItemURLGenerator.generateLabel(dataset, series);
    }
    Shape shape = getSeriesShape(series);
    Paint paint = getSeriesPaint(series);
    Paint outlinePaint = getSeriesOutlinePaint(series);
    Stroke outlineStroke = getSeriesOutlineStroke(series);

    // TODO: generate attributed label
    return new LegendItem(
        label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
  }
  /**
   * Draws a grid line against the domain axis.
   *
   * <p>Note that this default implementation assumes that the horizontal axis is the domain axis.
   * If this is not the case, you will need to override this method.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the Java2D value at which the grid line should be drawn.
   */
  public void drawDomainGridline(
      Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {

    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
      line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value);
    } else if (orientation == PlotOrientation.VERTICAL) {
      line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY());
    }

    Paint paint = plot.getDomainGridlinePaint();
    if (paint == null) {
      paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getDomainGridlineStroke();
    if (stroke == null) {
      stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);
  }
 /**
  * Returns a range axis for a plot.
  *
  * @param plot the plot.
  * @param index the axis index (<code>null</code> for the primary axis).
  * @return A range axis.
  */
 protected ValueAxis getRangeAxis(CategoryPlot plot, int index) {
   ValueAxis result = plot.getRangeAxis(index);
   if (result == null) {
     result = plot.getRangeAxis();
   }
   return result;
 }
 /**
  * Returns a domain axis for a plot.
  *
  * @param plot the plot.
  * @param index the axis index.
  * @return A domain axis.
  */
 protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {
   CategoryAxis result = plot.getDomainAxis(index);
   if (result == null) {
     result = plot.getDomainAxis();
   }
   return result;
 }
Example #10
0
    /** Draws a chart into {@link JFreeChart}. */
    public JFreeChart createChart() {
      final JFreeChart chart =
          ChartFactory.createLineChart(
              null, // chart title
              null, // unused
              null, // range axis label
              dataset, // data
              PlotOrientation.VERTICAL, // orientation
              true, // include legend
              true, // tooltips
              false // urls
              );

      chart.setBackgroundPaint(Color.white);
      chart.getLegend().setItemFont(CHART_FONT);

      final CategoryPlot plot = chart.getCategoryPlot();
      configurePlot(plot);

      configureRangeAxis((NumberAxis) plot.getRangeAxis());

      crop(plot);

      return chart;
    }
    @Override
    public void customize(JFreeChart chart, ReportParameters reportParameters) {

      BarRenderer barRenderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
      // barRenderer.setBaseSeriesVisible(false);//QUITA LAS BARRAS
      // barRenderer.setBaseSeriesVisibleInLegend(false);
      // barRenderer.setDrawBarOutline(false);
      barRenderer.setShadowVisible(false);
      barRenderer.setBarPainter(new CustomBarPainter());
      barRenderer.setItemMargin(0); // QUITA ESPACIOS ENTRE BARRA Y BARRA

      CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
      domainAxis.setUpperMargin(0);
      domainAxis.setLowerMargin(0);
      domainAxis.setCategoryMargin(0);
      domainAxis.setAxisLineVisible(false); // este es util

      Plot plot = chart.getPlot();
      // plot.setOutlineVisible(false);
      plot.setInsets(new RectangleInsets(0, 0, 0, 0)); // este sera util

      CategoryPlot categoryPlot = chart.getCategoryPlot();
      categoryPlot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
      // FAFO6categoryPlot.setRangeGridlinePaint(Color.WHITE);
      categoryPlot.setDomainGridlinesVisible(false);
      // FAFO5categoryPlot.setRangeGridlinesVisible(false);
      // categoryPlot.setBackgroundPaint(Color.white);
      categoryPlot.setOutlineVisible(false);

      ValueAxis valueAsix = categoryPlot.getRangeAxis();
      valueAsix.setAxisLineVisible(false); // este es muy util
      valueAsix.setRange(0, objDatosReporte.getIntMaxRango());
      valueAsix.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // este es muy util
    }
  /**
   * Creates a chart.
   *
   * @return A chart.
   */
  private static JFreeChart createChart() {

    CategoryDataset dataset1 = createDataset1();
    NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2();
    NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Category");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    JFreeChart chart =
        new JFreeChart(
            "Combined Domain Category Plot Demo", new Font("SansSerif", Font.BOLD, 12), plot, true);
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
  }
 private void saveChart(final DefaultCategoryDataset dataset) throws IOException {
   final JFreeChart chart =
       ChartFactory.createBarChart(
           "HtmlUnit implemented properties and methods for " + browserVersion_.getNickname(),
           "Objects",
           "Count",
           dataset,
           PlotOrientation.HORIZONTAL,
           true,
           true,
           false);
   final CategoryPlot plot = (CategoryPlot) chart.getPlot();
   final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
   axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   final LayeredBarRenderer renderer = new LayeredBarRenderer();
   plot.setRenderer(renderer);
   plot.setRowRenderingOrder(SortOrder.DESCENDING);
   renderer.setSeriesPaint(0, new GradientPaint(0, 0, Color.green, 0, 0, new Color(0, 64, 0)));
   renderer.setSeriesPaint(1, new GradientPaint(0, 0, Color.blue, 0, 0, new Color(0, 0, 64)));
   renderer.setSeriesPaint(2, new GradientPaint(0, 0, Color.red, 0, 0, new Color(64, 0, 0)));
   ImageIO.write(
       chart.createBufferedImage(1200, 2400),
       "png",
       new File(
           getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".png"));
 }
Example #14
0
  /**
   * Draws the outline for the plot.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area inside the axes.
   */
  @Override
  public void drawOutline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(this.xOffset);
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(this.xOffset);

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(this.yOffset);
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(this.yOffset);

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    // put an outline around the data area...
    Stroke outlineStroke = plot.getOutlineStroke();
    Paint outlinePaint = plot.getOutlinePaint();
    if ((outlineStroke != null) && (outlinePaint != null)) {
      g2.setStroke(outlineStroke);
      g2.setPaint(outlinePaint);
      g2.draw(clip);
    }
  }
Example #15
0
  /**
   * Draws a grid line against the domain axis.
   *
   * @param g2 the graphics device.
   * @param plot the plot.
   * @param dataArea the area for plotting data (not yet adjusted for any 3D effect).
   * @param value the Java2D value at which the grid line should be drawn.
   */
  @Override
  public void drawDomainGridline(
      Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {

    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
      double y0 = value;
      double y1 = value - getYOffset();
      double x0 = dataArea.getMinX();
      double x1 = x0 + getXOffset();
      double x2 = dataArea.getMaxX();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x2, y1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      double x0 = value;
      double x1 = value + getXOffset();
      double y0 = dataArea.getMaxY();
      double y1 = y0 - getYOffset();
      double y2 = dataArea.getMinY();
      line1 = new Line2D.Double(x0, y0, x1, y1);
      line2 = new Line2D.Double(x1, y1, x1, y2);
    }
    g2.setPaint(plot.getDomainGridlinePaint());
    g2.setStroke(plot.getDomainGridlineStroke());
    g2.draw(line1);
    g2.draw(line2);
  }
  public void loadDataToGrafik() throws IOException {
    DefaultCategoryDataset dataset = (DefaultCategoryDataset) this.generateData();
    chart =
        ChartFactory.createBarChart(
            "Statistik Pendidikan Dosen",
            "Prodi",
            "Jumlah Dosen",
            dataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    chart.setBackgroundPaint(new Color(0xCC, 0xFF, 0xCC));

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final CategoryItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.red);
    renderer1.setSeriesPaint(1, Color.yellow);
    renderer1.setSeriesPaint(2, Color.green);
    BarRenderer br = (BarRenderer) renderer1;
    br.setShadowVisible(false);

    br.setShadowVisible(false);
    BufferedImage bi = chart.createBufferedImage(900, 1500, BufferedImage.TRANSLUCENT, null);
    byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
    AImage image = new AImage("Bar Chart", bytes);
    chartImg.setContent(image);
    btnExport.setDisabled(false);
  }
  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
  /** Replaces the chart's dataset and then checks that the new dataset is OK. */
  public void testReplaceDataset() {

    // create a dataset...
    Number[][] data =
        new Integer[][] {
          {new Integer(-30), new Integer(-20)},
          {new Integer(-10), new Integer(10)},
          {new Integer(20), new Integer(30)}
        };

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue(
        "Expecting the lower bound of the range to be around -30: " + range.getLowerBound(),
        range.getLowerBound() <= -30);
    assertTrue(
        "Expecting the upper bound of the range to be around 30: " + range.getUpperBound(),
        range.getUpperBound() >= 30);
  }
  /**
   * Creates a chart.
   *
   * @param dataset the dataset.
   * @return The chart.
   */
  private static JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart =
        ChartFactory.createStackedBarChart3D(
            "Stacked Bar Chart 3D Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    IntervalMarker m =
        new IntervalMarker(
            5.0, 10.0, Color.gray, new BasicStroke(0.5f), Color.blue, new BasicStroke(0.5f), 0.5f);
    plot.addRangeMarker(m);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    renderer.setBaseNegativeItemLabelPosition(
        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    return chart;
  }
  /**
   * Creates a chart.
   *
   * @return A chart.
   */
  private static JFreeChart createChart(String symbol) {

    CategoryDataset dataset1 = createDataset1(symbol);
    NumberAxis rangeAxis1 = new NumberAxis("Jumlah");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2(symbol);
    NumberAxis rangeAxis2 = new NumberAxis("Jumlah");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    CategoryAxis domainAxis = new CategoryAxis("Tahun Periksa");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    //             CombinedCategoryPlot plot = new CombinedCategoryPlot(
    //                     domainAxis, new NumberAxis("Range"));
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    JFreeChart result = new JFreeChart("", new Font("SansSerif", Font.BOLD, 10), plot, true);
    return result;
  }
Example #21
0
  /**
   * Creates a vertical 3D-effect bar chart with default settings.
   *
   * @param title the chart title.
   * @param categoryAxisLabel the label for the category axis.
   * @param valueAxisLabel the label for the value axis.
   * @param data the dataset for the chart.
   * @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 vertical 3D-effect bar chart.
   */
  public static JFreeChart createBarChart3D(
      String title,
      java.awt.Font titleFont,
      String categoryAxisLabel,
      String valueAxisLabel,
      CategoryDataset data,
      PlotOrientation orientation,
      boolean legend,
      boolean tooltips,
      boolean urls,
      CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    BarRenderer3D renderer = new BarRenderer3D();

    // renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    if (tooltips) {
      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
      renderer.setItemURLGenerator(urlGenerator);
    }

    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    plot.setForegroundAlpha(0.75f);

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

    return chart;
  }
 private JFreeChart createChart(CategoryDataset setCategory) {
   JFreeChart chart =
       ChartFactory.createBarChart(
           this.chartTitle, "", "", setCategory, PlotOrientation.VERTICAL, true, true, false);
   CategoryPlot plot = (CategoryPlot) chart.getPlot();
   plot.addRangeMarker(ChartUtil.getAverageMarker(this.average), Layer.FOREGROUND);
   BookModel model = this.mainFrame.getBookModel();
   Session session = model.beginTransaction();
   StrandDAOImpl daoStrand = new StrandDAOImpl(session);
   List strands = daoStrand.findAll();
   model.commit();
   Color[] colors = new Color[strands.size()];
   int i = 0;
   Object iObject = strands.iterator();
   while (((Iterator) iObject).hasNext()) {
     Strand strand = (Strand) ((Iterator) iObject).next();
     colors[i] = ColorUtil.darker(strand.getJColor(), 0.25D);
     i++;
   }
   iObject = (BarRenderer) plot.getRenderer();
   for (int j = 0; j < setCategory.getRowCount(); j++) {
     Color color = colors[(j % colors.length)];
     ((BarRenderer) iObject).setSeriesPaint(j, color);
   }
   return chart;
 }
 private JFreeChart formChart() {
   DefaultCategoryDataset data = new DefaultCategoryDataset();
   String dateString = request.getParameter("date");
   Date date = null;
   if (dateString != null && (!dateString.equals("null"))) {
     date = DayTransformer.transform(dateString);
   } else {
     date = new Date(System.currentTimeMillis());
   }
   String[][] storeSellingDis =
       saleperformanceManage.getStoreSellingDis(DayTransformer.transformToMonth(date));
   for (int i = 0; i < storeSellingDis.length; i++) {
     data.setValue(
         Double.parseDouble(storeSellingDis[i][1]), storeSellingDis[i][0], storeSellingDis[i][0]);
   }
   JFreeChart barChart =
       ChartFactory.createBarChart(
           "店铺销售分布图", "店铺名称", "销售额", data, PlotOrientation.VERTICAL, true, true, false);
   CategoryPlot plot = (CategoryPlot) barChart.getCategoryPlot();
   BarRenderer renderer = (BarRenderer) plot.getRenderer();
   // 显示条目标签
   renderer.setBaseItemLabelsVisible(true);
   // 设置条目标签生成器,在JFreeChart1.0.6之前可以通过renderer.setItemLabelGenerator(CategoryItemLabelGenerator
   // generator)方法实现,但是从版本1.0.6开始有下面方法代替
   renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
   // 设置条目标签显示的位置,outline表示在条目区域外,baseline_center表示基于基线且居中
   renderer.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
   barChart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15)); // 设置引用标签字体
   barChart.getTitle().setFont(new Font("华文行楷", Font.BOLD, 32));
   return barChart;
 }
  private static void generateChart(
      String benchmark, DefaultCategoryDataset dataset, int benchmarkCount) {
    JFreeChart chart =
        ChartFactory.createBarChart(
            benchmark,
            "framework",
            "throughput",
            dataset,
            PlotOrientation.HORIZONTAL,
            true,
            false,
            false);

    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setItemMargin(0);
    notSoUglyPlease(chart);

    String pngFile = getOutputName(benchmark);

    try {
      int height = 100 + benchmarkCount * 20;
      ChartUtilities.saveChartAsPNG(new File(pngFile), chart, 700, height);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 private static JFreeChart createChart(CategoryDataset categorydataset) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart3D(
           "Stacked Bar Chart 3D Demo 2",
           "Category",
           "Value",
           categorydataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
   numberaxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
   StackedBarRenderer3D stackedbarrenderer3d = (StackedBarRenderer3D) categoryplot.getRenderer();
   stackedbarrenderer3d.setRenderAsPercentages(true);
   stackedbarrenderer3d.setDrawBarOutline(false);
   stackedbarrenderer3d.setBaseItemLabelGenerator(
       new StandardCategoryItemLabelGenerator(
           "{3}", NumberFormat.getIntegerInstance(), new DecimalFormat("0.0%")));
   stackedbarrenderer3d.setBaseItemLabelsVisible(true);
   stackedbarrenderer3d.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   stackedbarrenderer3d.setBaseNegativeItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
   return jfreechart;
 }
Example #26
0
  /**
   * Creates a stacked area chart with default settings.
   *
   * @param title the chart title.
   * @param categoryAxisLabel the label for the category axis.
   * @param valueAxisLabel the label for the value axis.
   * @param data the dataset for the chart.
   * @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 an area chart.
   */
  public static JFreeChart createStackedAreaChart(
      String title,
      java.awt.Font titleFont,
      String categoryAxisLabel,
      String valueAxisLabel,
      CategoryDataset data,
      PlotOrientation orientation,
      boolean legend,
      boolean tooltips,
      boolean urls,
      CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    StackedAreaRenderer renderer = new StackedAreaRenderer();
    if (tooltips) {
      renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
      renderer.setItemURLGenerator(urlGenerator);
    }

    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;
  }
 /**
  * Returns the drawing supplier from the plot.
  *
  * @return The drawing supplier (possibly <code>null</code>).
  */
 public DrawingSupplier getDrawingSupplier() {
   DrawingSupplier result = null;
   CategoryPlot cp = getPlot();
   if (cp != null) {
     result = cp.getDrawingSupplier();
   }
   return result;
 }
 /** Check that setting a tool tip generator for a series does override the default generator. */
 public void testSetSeriesToolTipGenerator() {
   CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
   CategoryItemRenderer renderer = plot.getRenderer();
   StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator();
   renderer.setSeriesToolTipGenerator(0, tt);
   CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
   assertTrue(tt2 == tt);
 }
 /** Check that setting a URL generator for a series does override the default generator. */
 public void testSetSeriesURLGenerator() {
   CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
   CategoryItemRenderer renderer = plot.getRenderer();
   StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator();
   renderer.setSeriesItemURLGenerator(0, url1);
   CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0);
   assertTrue(url2 == url1);
 }
Example #30
0
 /**
  * 更新图表显示
  *
  * @param chart
  */
 private void updatePlot(JFreeChart chart) {
   // 图表
   CategoryPlot categoryPlot = chart.getCategoryPlot();
   // y轴
   ValueAxis valueAxis = categoryPlot.getRangeAxis();
   // Y轴数据范围
   valueAxis.setRangeAboutValue(200, 1000);
 }