Java Code Examples for org.jfree.chart.axis.ValueAxis#setLowerMargin()

The following examples show how to use org.jfree.chart.axis.ValueAxis#setLowerMargin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests the the lower and upper margin settings produce the expected
 * results.
 */
public void testAxisMargins() {
    XYSeries series = new XYSeries("S1");
    series.add(100.0, 1.1);
    series.add(200.0, 2.2);
    XYSeriesCollection dataset = new XYSeriesCollection(series);
    dataset.setIntervalWidth(0.0);
    JFreeChart chart = ChartFactory.createScatterPlot(
        "Title", "X", "Y", dataset, false);
    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Range r = domainAxis.getRange();
    assertEquals(110.0, r.getLength(), EPSILON);
    domainAxis.setLowerMargin(0.10);
    domainAxis.setUpperMargin(0.10);
    r = domainAxis.getRange();
    assertEquals(120.0, r.getLength(), EPSILON);
}
 
Example 2
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a time series chart.  A time series chart is an
 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a
 * {@link NumberAxis} for the y-axis.  The default renderer is an
 * {@link XYLineAndShapeRenderer}. A convenient dataset to use with this
 * chart is a {@link TimeSeriesCollection}.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A time series chart.
 */
public static JFreeChart createTimeSeriesChart(String title,
        String timeAxisLabel, String valueAxisLabel, XYDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02);  // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);  // override default
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    XYToolTipGenerator toolTipGenerator = null;
    toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,
            false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    plot.setRenderer(renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 3
Source File: ValueAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests the the lower and upper margin settings produce the expected 
 * results.
 */
public void testAxisMargins() {
    XYSeries series = new XYSeries("S1");
    series.add(100.0, 1.1);
    series.add(200.0, 2.2);
    XYSeriesCollection dataset = new XYSeriesCollection(series);
    dataset.setIntervalWidth(0.0);
    JFreeChart chart = ChartFactory.createScatterPlot(
        "Title", "X", "Y", dataset, PlotOrientation.VERTICAL, 
        false, false, false
    );
    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Range r = domainAxis.getRange();
    assertEquals(110.0, r.getLength(), EPSILON);
    domainAxis.setLowerMargin(0.10);
    domainAxis.setUpperMargin(0.10);
    r = domainAxis.getRange();
    assertEquals(120.0, r.getLength(), EPSILON);
}
 
Example 4
Source File: RenderUtils.java    From heroic with Apache License 2.0 5 votes vote down vote up
private static JFreeChart buildChart(
    final String title, final XYDataset lineAndShape, final XYDataset interval,
    final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer
) {
    final ValueAxis timeAxis = new DateAxis();
    timeAxis.setLowerMargin(0.02);
    timeAxis.setUpperMargin(0.02);

    final NumberAxis valueAxis = new NumberAxis();
    valueAxis.setAutoRangeIncludesZero(false);

    final XYPlot plot = new XYPlot();

    plot.setDomainAxis(0, timeAxis);
    plot.setRangeAxis(0, valueAxis);

    plot.setDataset(0, lineAndShape);
    plot.setRenderer(0, lineAndShapeRenderer);

    plot.setDomainAxis(1, timeAxis);
    plot.setRangeAxis(1, valueAxis);

    plot.setDataset(1, interval);
    plot.setRenderer(1, intervalRenderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
}
 
Example 5
Source File: XYTitleAnnotationDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        false,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(200, 200, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.BOTTOM);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, 
            RectangleAnchor.BOTTOM_RIGHT);
    
    ta.setMaxWidth(0.48);
    plot.addAnnotation(ta);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setLowerMargin(0.35);
    return chart;

}