Example usage for org.jfree.chart.plot XYPlot setAxisOffset

List of usage examples for org.jfree.chart.plot XYPlot setAxisOffset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setAxisOffset.

Prototype

public void setAxisOffset(RectangleInsets offset) 

Source Link

Document

Sets the axis offsets (gap between the data area and the axes) and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:edu.ucla.stat.SOCR.chart.SuperXYChart.java

/**
 * Creates a chart./*from   w w  w. j a  va 2 s.c o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

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

    return chart;

}

From source file:se.six.jmeter.visualizer.statagg.StatAggVisualizer.java

private JFreeChart createChart() {
    setupDatasets();//from   ww  w . j av a 2s . c  o  m

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "ThroughPut", _dataSet1, true,
            true, false);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    //axis.setFixedAutoRange(12 * 3600 * 1000);  // 12 Hours

    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.BLACK);

    final NumberAxis axis2 = new NumberAxis("Response Time");
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, _dataSet2);
    plot.mapDatasetToRangeAxis(1, 1);

    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, new Color(0, 153, 255));
    plot.setRenderer(1, renderer2);

    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.DotChart.java

/**
 * Creates a chart.//  w w  w. jav  a2 s  .c o  m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart1(XYDataset dataset) {
    //System.out.println("createChart1 called");
    //   create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "", // x axis label domain
            rangeLabel, // y axis label  range
            dataset, // data
            PlotOrientation.HORIZONTAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setBaseLinesVisible(false);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

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

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(true);
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setUpperMargin(5);
    domainAxis.setLowerMargin(0.01);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    try {
        //   System.out.println("setting the common RangeAxis to null");
        common_rangeAxis = null;
        common_rangeAxis = (NumberAxis) rangeAxis.clone();
        //   System.out.println("creating the common RangeAxis");
    } catch (CloneNotSupportedException e) {
        System.out.println("CloneNotSupportedException!, exception caught");
    }

    return chart;
}

From source file:domain.Grafica.java

public JFreeChart createChart(XYDataset dataset) {
    /*//from ww w . j  a va  2  s  .c o m
     ///*
     NumberAxis numberaxis = new NumberAxis("");
     numberaxis.setAutoRangeIncludesZero(false);
            
     DateAxis dateaxis = new DateAxis("");
            
     NumberAxis numberaxis1 = new NumberAxis("");
     numberaxis1.setAutoRangeIncludesZero(false);
            
     XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
            
     XYPlot xyplot = new XYPlot(dataset, dateaxis, numberaxis1, xysplinerenderer);
     // xyplot.setBackgroundPaint(new Color(238, 242, 250));//
     // xyplot.setDomainGridlinePaint(new Color(255, 255, 255));
     // xyplot.setRangeGridlinePaint(new Color(238, 242, 250));
     xyplot.getRenderer().setSeriesPaint(0, Color.RED);
     xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
     XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
     renderer.setSeriesShapesVisible(0, true);//FIXME Dots
            
     //  xyplot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
     JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, xyplot, false);
     jfreechart.setBackgroundPaint(Color.white);
            
     DateAxis axis = (DateAxis) xyplot.getDomainAxis();
     axis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa"));
            
     xyplot.getRangeAxis().setUpperBound(maxPeso * 1.25);
     xyplot.getRangeAxis().setLowerBound(minPeso * 0.75);
     cargarImagen();
     // xyplot.setBackgroundImage(i);
     //jfreechart.setBackgroundImage(i);
     return jfreechart;
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title
            "Fecha/Hora", // x-axis label
            "Pesos(Kg.)", // 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.white);
    plot.setDomainGridlinePaint(Color.GRAY);
    plot.setRangeGridlinePaint(Color.GRAY);
    /*         plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
     plot.setDomainCrosshairVisible(false);
     plot.setRangeCrosshairVisible(false);
     */
    plot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

    XYItemRenderer r = plot.getRenderer();

    if (r instanceof XYLineAndShapeRenderer) {

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
    }

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    // range.setAutoRangeIncludesZero(true);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss"));

    plot.getRangeAxis().setUpperBound(maxPeso * 1.25);
    plot.getRangeAxis().setLowerBound(minPeso * 0.75);

    return chart;

}

From source file:wattsup.jsdk.ui.ChartPanelSupport.java

/**
 * Clean the values of the chart./*from   ww w  .j av  a  2s .  co m*/
 * 
 * @see #createChart()
 */
public void cleanChart() {
    this.chart_.removeLegend();
    this.chartPanel_.setBorder(null);

    cleanLabels();

    DateAxis localDateAxis = (DateAxis) ((XYPlot) this.chart_.getPlot()).getDomainAxis();
    localDateAxis.setTickLabelsVisible(false);
    localDateAxis.setTickMarksVisible(false);
    localDateAxis.setAxisLineVisible(false);

    ValueAxis localValueAxis = ((XYPlot) this.chart_.getPlot()).getRangeAxis();
    localValueAxis.setTickLabelsVisible(false);
    localValueAxis.setTickMarksVisible(false);
    localValueAxis.setAxisLineVisible(false);

    XYPlot localXYPlot = (XYPlot) this.chart_.getPlot();
    localXYPlot.setDomainGridlineStroke(this.defaultLineStroke_);
    localXYPlot.setDomainGridlinesVisible(true);
    localXYPlot.setRangeGridlineStroke(this.defaultLineStroke_);
    localXYPlot.setRangeGridlinesVisible(true);

    localXYPlot.setAxisOffset(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D));
    localXYPlot.setInsets(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D), true);
}

From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformationFamilyChart.java

/**
 * Creates a chart.//from  w w w .  j av a2s.  c  o  m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    chartTitle = "Power Transform Chart";
    //   create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Power Transform Chart",      // chart title
            domainLabel, // x axis label 
            rangeLabel, // y axis label  
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips 
            false // urls
    );
    toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
    renderer.setBaseLinesVisible(true);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

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

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    //  domainAxis.setTickLabelsVisible(false);
    // domainAxis.setTickMarksVisible(false);      
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    return chart;
}

From source file:daylightchart.daylightchart.chart.DaylightChart.java

/**
 * Creates the daylight chart.//from ww w  . j a va  2 s .  co m
 */
private void createChart(final Options options) {

    setBackgroundPaint(Color.white);

    final XYPlot plot = getXYPlot();

    // Set the first renderer, so that the grid lines can be shown
    plot.setRenderer(new StandardXYItemRenderer());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setBackgroundPaint(ChartConfiguration.nightColor);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    createMonthsAxis(plot);
    createHoursAxis(plot);

    // Create a marker region for daylight savings time
    if (riseSetData.usesDaylightTime()) {
        createDSTMarker(plot);
    }

    createBandsInPlot(plot);

    ChartOrientation chartOrientation = ChartOrientation.STANDARD;
    if (options != null) {
        chartOrientation = options.getChartOrientation();
    }
    adjustForChartOrientation(chartOrientation);

    final Options optionsNotNull;
    if (options == null) {
        optionsNotNull = new Options();
    } else {
        optionsNotNull = options;
    }
    createTitles(optionsNotNull.getChartOptions(), ChartConfiguration.chartFont.deriveFont(Font.BOLD, 18));

    createLegend(optionsNotNull, ChartConfiguration.chartFont.deriveFont(Font.PLAIN, 12));

}

From source file:org.tolven.web.ChartAction.java

/**
 * Create Growth Chart/*from ww w  . j  a v a 2 s .  c o m*/
 * 
 * @author Suja
 * added on 02/01/2011
 * @param type - 1: Height & 2: Weight
 * @return
 */
public JFreeChart createChart(int type) {
    long patientId = Long.parseLong(getRequestParameter("element").toString().split(":")[1].split("-")[1]);
    MenuData patMD = getMenuLocal().findMenuDataItem(patientId);
    int age = 0;
    int gender = 1;
    Date dob = null;
    if (patMD != null) {
        DateFormat df = new SimpleDateFormat("yyyy");
        dob = patMD.getDate01();
        Date cur = new Date();
        age = Integer.parseInt(df.format(cur)) - Integer.parseInt(df.format(dob));
        if (patMD.getString04().equals("Male"))
            gender = 1;
        else
            gender = 2;
    }

    // create dataset
    XYDataset dataset = createDataset(type, gender, age, dob);
    String title = "";
    if (type == 1 && age < 3)
        title = "Height birth to 36 Months Old " + (gender == 1 ? "Male" : "Female");
    else if (type == 1 && age >= 3)
        title = "Height 2-20 Year Old " + (gender == 1 ? "Male" : "Female");
    else if (type == 2 && age < 3)
        title = "Weight birth to 36 Months Old " + (gender == 1 ? "Male" : "Female");
    else if (type == 2 && age >= 3)
        title = "Weight 2-20 Year Old " + (gender == 1 ? "Male" : "Female");
    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "X-Value", // x-axis label
            "Y-Value", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

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

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 1; i < 10; i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, false);
    }
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    plot.setDomainAxis(new NumberAxis("Age (Months)"));
    plot.setRangeAxis(new NumberAxis((type == 1 ? "Height (Centimeters)" : "Weight (Kilograms)")));
    return chart;
}

From source file:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java

/**
 * Creates a chart./*from  w w  w . j av  a 2  s .  c o  m*/
 *
 * @param dataset1  a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset, long lastentry) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "time", // x-axis label
            "temperature", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

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

    NumberAxis axis1 = new NumberAxis(getAxisName());
    axis1.setAutoRangeIncludesZero(isIncludeZero());
    plot.setRangeAxis(0, axis1);

    plot.setDataset(0, dataset);
    plot.mapDatasetToRangeAxis(1, 0);

    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);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    r1.setSeriesPaint(0, Color.BLUE);
    r1.setSeriesPaint(1, Color.RED);
    r1.setSeriesPaint(2, Color.GREEN);

    //plot.setDomainAxis(new NumberAxis("time"));
    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = getRangeBegin(lastentry);
    long end = getRangeEnd(lastentry);

    plot.getDomainAxis().setRange(begin, end);

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformXYScatterChart.java

/**
 * Creates a chart./*from   ww w  .j  a  v a  2 s  . co m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Power Transformed XYScatter Chart",      // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    // renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

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

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setXSummary(dataset);
    return chart;

}