private JFreeChart createChart(final GraphBuilder builder) {
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            builder.graphTitle(),
            builder.xAxisLabel(),
            builder.yAxisLabel(),
            builder.dataset(),
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    // rangeAxis.setRange(0,20);

    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);

    if (builder.yRange0To1()) {
      chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
    }

    return chart;
  }
Esempio n. 2
0
 private static JFreeChart createChart(XYDataset xydataset) {
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Legal & General Unit Trust Prices",
           "Date",
           "Price Per Unit",
           xydataset,
           true,
           true,
           false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   xyplot.setDomainCrosshairVisible(true);
   xyplot.setRangeCrosshairVisible(true);
   org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
   if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
     XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
     xylineandshaperenderer.setBaseShapesVisible(true);
     xylineandshaperenderer.setBaseShapesFilled(true);
     xylineandshaperenderer.setBaseItemLabelsVisible(true);
   }
   PeriodAxis periodaxis = new PeriodAxis("Date");
   periodaxis.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
   periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class);
   PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[3];
   aperiodaxislabelinfo[0] =
       new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"));
   aperiodaxislabelinfo[1] =
       new PeriodAxisLabelInfo(
           org.jfree.data.time.Month.class,
           new SimpleDateFormat("MMM"),
           new RectangleInsets(2D, 2D, 2D, 2D),
           new Font("SansSerif", 1, 10),
           Color.blue,
           false,
           new BasicStroke(0.0F),
           Color.lightGray);
   aperiodaxislabelinfo[2] =
       new PeriodAxisLabelInfo(org.jfree.data.time.Year.class, new SimpleDateFormat("yyyy"));
   periodaxis.setLabelInfo(aperiodaxislabelinfo);
   xyplot.setDomainAxis(periodaxis);
   ChartUtilities.applyCurrentTheme(jfreechart);
   return jfreechart;
 }