private static JFreeChart createChart(TableXYDataset tablexydataset) {
   DateAxis dateaxis = new DateAxis("Date");
   dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
   dateaxis.setLowerMargin(0.01D);
   dateaxis.setUpperMargin(0.01D);
   NumberAxis numberaxis = new NumberAxis("Count");
   numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
   numberaxis.setUpperMargin(0.10000000000000001D);
   StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D);
   stackedxybarrenderer.setDrawBarOutline(false);
   stackedxybarrenderer.setBaseItemLabelsVisible(true);
   stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
   stackedxybarrenderer.setBasePositiveItemLabelPosition(
       new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
   stackedxybarrenderer.setBaseToolTipGenerator(
       new StandardXYToolTipGenerator(
           "{0} : {1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0")));
   XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
   JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot);
   jfreechart.removeLegend();
   jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003"));
   TextTitle texttitle =
       new TextTitle(
           "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html",
           new Font("Dialog", 0, 8));
   jfreechart.addSubtitle(texttitle);
   jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
   LegendTitle legendtitle = new LegendTitle(xyplot);
   legendtitle.setBackgroundPaint(Color.white);
   legendtitle.setFrame(new BlockBorder());
   legendtitle.setPosition(RectangleEdge.BOTTOM);
   jfreechart.addSubtitle(legendtitle);
   return jfreechart;
 }
Ejemplo n.º 2
0
  /**
   * Creates a sample chart.
   *
   * @param dataset the dataset for the chart.
   * @return a sample chart.
   */
  private static JFreeChart createChart(TableXYDataset dataset) {

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);

    NumberAxis rangeAxis = new NumberAxis("Tonnes");
    // rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    rangeAxis.setNumberFormatOverride(new DecimalFormat("0.0%"));
    StackedXYBarRenderer renderer = new StackedXYBarRenderer(0.30);
    renderer.setRenderAsPercentages(true);
    renderer.setDrawBarOutline(false);

    renderer.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            "{0} : {1} = {2} tonnes", new SimpleDateFormat("yyyy"), new DecimalFormat("#,##0")));

    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    JFreeChart chart = new JFreeChart("Waste Management", plot);
    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(new TextTitle("St Albans City and District Council"));

    ChartUtilities.applyCurrentTheme(chart);

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, new Color(64, 0, 0), 0.0f, 0.0f, Color.red);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, new Color(0, 64, 0), 0.0f, 0.0f, Color.green);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setGradientPaintTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    return chart;
  }