Example usage for org.jfree.chart.axis NumberAxis getUpperBound

List of usage examples for org.jfree.chart.axis NumberAxis getUpperBound

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis getUpperBound.

Prototype

public double getUpperBound() 

Source Link

Document

Returns the upper bound for the axis range.

Usage

From source file:eu.choreos.vv.chart.XYChart.java

private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );// w w w  .ja v a2 s.  c om

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    return chart;
}

From source file:eu.choreos.vv.chart.YIntervalChart.java

private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*www.j  ava2s  .co m*/

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    DeviationRenderer renderer = new DeviationRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    //TODO: render the deviation with the same color as the line
    //        renderer.setBaseFillPaint(new Color(255, 200, 200));
    //        renderer.setUseOutlinePaint(flag);
    //        renderer.setUseFillPaint(flag);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    //TODO: fix the visible area to show the deviation

    return chart;
}

From source file:org.cyberoam.iview.charts.XYLine.java

/**
 * This method generates JFreeChart instance for XYLine chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from URL.
 * @return jfreechart instance with iView Customization.
 *///www. ja v  a 2 s.com
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    try {
        ReportColumnBean reportColumnBean = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        XYDataset dataset = null;
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries(reportBean.getTitle());
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBean.getDbColumnName();
        String xColumnName = reportColumnBean.getColumnName();
        //Wheather DataLink is Given For X Axis column
        if (reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        String yColumnName = reportColumnBean.getColumnName();
        //if DataLink is not Given For X Axis column then Check of Y Axis Column
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        String zColumnDbname = reportColumnBean.getDbColumnName();
        //Preparing DataSet
        String data = "";
        rsw.beforeFirst();
        while (rsw.next()) {
            data = rsw.getString(xColumnDBname);
            series.add(Long.parseLong((data).substring(data.length() - 2)),
                    new Long(rsw.getLong(yColumnDBname)).longValue());
        }
        seriesCollection.addSeries(series);

        dataset = seriesCollection;
        // create the chart...
        chart = ChartFactory.createXYLineChart("", // chart title
                "", // domain axis label
                "", seriesCollection, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         * Additional iView Customization.
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        //Get a reference to the plot for further customisation...
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(new Color(245, 245, 245));
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setForegroundAlpha(0.7f);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);

        Axis domainAxis = plot.getDomainAxis();
        domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        domainAxis.setTickMarksVisible(false);
        domainAxis.setAxisLineVisible(false);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        renderer.setSeriesStroke(0, new BasicStroke(1));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return chart;
}

From source file:org.cyberoam.iview.charts.CustomCategoryAxis.java

/**
 * This method generates JFreeChart instance for 3D Bar chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @return jfreechart instance with iView Customization.
 */// w ww  .j a  v a  2  s.c o  m
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    JFreeChart chart = null;
    boolean isPDF = false;
    try {
        if (request == null) {
            isPDF = true;
        }
        /*
         * Create data set based on rsw object.
         */
        ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
        ReportColumnBean reportColumnBeanX, reportColumnBeanY = null;

        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        if (reportColumnBeanX.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId());
        }

        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        rsw.beforeFirst();
        int i = 0;
        DecimalFormat placeHolder = new DecimalFormat("00");
        String xData = null;
        String graphurl = "";
        HashMap<Integer, String> urlmap = new HashMap<Integer, String>();
        while (rsw.next()) {
            xData = rsw.getString(reportColumnBeanX.getDbColumnName());
            if (dataLinkBean != null && request != null) {
                //datalink id is non -1 in tblcolumnreport table means another report is avaialble so set url 
                // here multiple url possible bec multiple record so take hashmap and store url. 
                // we have dataset but dataset is occupied.
                graphurl = dataLinkBean.generateURLForChart(rsw, request);
                urlmap.put(new Integer(i), graphurl);
            }
            //dataset second arugument use for bar line of graph and third argument give name of graph
            dataset.addValue(new Long(rsw.getLong(reportColumnBeanY.getDbColumnName())), "",
                    placeHolder.format(i) + xData);
            i++;
        }
        // we define object of CustomURLGeneratorForBarChart and if datalinkid is not -1 then it object define for link
        CustomURLGeneratorForBarChart customURLGeneratorForBarChart = null;
        if (dataLinkBean != null && request != null) {
            customURLGeneratorForBarChart = new CustomURLGeneratorForBarChart(
                    dataLinkBean.generateURLForChart(request), reportColumnBeanX.getDbColumnName());
            customURLGeneratorForBarChart.setUrlMap(urlmap);
        }
        /*
         * Create the jfree chart object.
         */
        String title = isPDF ? reportBean.getTitle() : "";
        chart = ChartFactory.createBarChart3D(title, // chart title
                "", // domain axis label
                "", dataset, // data            
                PlotOrientation.HORIZONTAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );

        /*
         *Setting additional customization to the chart. 
         */
        //Set background color
        chart.setBackgroundPaint(Color.white);
        //Get a reference to the plot for further customisation
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setForegroundAlpha(0.8f);
        plot.setDomainGridlineStroke(new BasicStroke(2));
        plot.setOutlineVisible(false);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBeanY.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(false);
        rangeAxis.setLabel(reportColumnBeanY.getColumnName());
        rangeAxis.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 12));
        rangeAxis.setLabelPaint(new Color(35, 139, 199));

        CustomCategoryAxis catAxis = new CustomCategoryAxis();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setAxisLineVisible(false);
        catAxis.setLabel(reportColumnBeanX.getColumnName());
        catAxis.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 12));
        catAxis.setLabelPaint(new Color(35, 139, 199));
        catAxis.setLabelFormat(reportColumnBeanX.getColumnFormat());

        plot.setDomainAxis(catAxis);

        //Set custom color for the chart.         
        CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { new Color(254, 211, 41),
                new Color(243, 149, 80), new Color(199, 85, 82), new Color(181, 105, 152),
                new Color(69, 153, 204), new Color(155, 212, 242), new Color(52, 172, 100),
                new Color(164, 212, 92), new Color(177, 155, 138), new Color(149, 166, 141) });

        plot.setRenderer(renderer);

        BarRenderer renderer2 = (BarRenderer) plot.getRenderer();
        renderer2.setDrawBarOutline(false);
        renderer2.setBaseItemLabelsVisible(true);
        renderer2.setMaximumBarWidth(0.04);

        if (dataLinkBean != null && request != null) {
            renderer.setBaseItemURLGenerator(customURLGeneratorForBarChart);
            //renderer.setBaseItemURLGenerator(new CustomURLGeneratorForBarChart(dataLinkBean.generateURLForChart(request),reportColumnBeanX.getDbColumnName()));
        }
        renderer.setBaseToolTipGenerator(new CustomToolTipGenerator());
        renderer.setBaseToolTipGenerator(new CustomToolTipGenerator());
        renderer.setBaseToolTipGenerator(
                new CustomToolTipGenerator("{2} " + reportColumnBeanY.getColumnName()));
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("Bar3D.e:" + e, e);
    }
    return chart;
}

From source file:org.cyberoam.iview.charts.CustomCategoryDataset.java

/**
 * This method generates JFreeChart instance for 3D Stacked Column chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @return jfreechart instance with iView Customization.
 *//*  w  w  w  .  j av  a 2  s  . c  om*/
public static JFreeChart getChart(int reportId, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportId);
    JFreeChart chart = null;
    try {
        /*
         * Create data set based on rsw object.
         */
        ReportColumnBean reportColumnBean = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        CustomCategoryDataset dataset = new CustomCategoryDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBean.getDbColumnName();
        reportColumnBean.getColumnName();

        //Wheather DataLink is Given For X Axis column
        if (reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }

        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        reportColumnBean.getColumnName();

        //if DataLink is not Given For X Axis column then Check of Y Axis Column
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        //String zColumnDbname = reportColumnBean.getDbColumnName();
        String xData = null, zData = null;
        //Preparing DataSet
        rsw.beforeFirst();
        while (rsw.next()) {
            xData = rsw.getString(xColumnDBname);
            //zData = rsw.getString(zColumnDbname);
            zData = TabularReportGenerator.getFormattedColumn(reportColumnBean.getColumnFormat(),
                    reportColumnBean.getDbColumnName(), rsw);
            if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData))
                xData = "N/A";
            dataset.addValue(new Long(rsw.getLong(yColumnDBname)), zData, xData, rsw.getString("deviceid"));
        }

        //Create the jfree chart instance.
        chart = ChartFactory.createStackedBarChart3D("", // chart title
                "", "", dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         *Setting additional customization to the chart. 
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);
        //Get a reference to the plot for further customisation...
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(new Color(245, 245, 245));
        plot.setDomainGridlinePaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);

        Axis domainAxis = plot.getDomainAxis();
        domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        domainAxis.setTickMarksVisible(false);
        domainAxis.setAxisLineVisible(false);

        LegendTitle legendTitle = chart.getLegend();
        legendTitle.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 11));

        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);
        renderer.setMaximumBarWidth(0.05);

        renderer.setSeriesPaint(0, new Color(24, 112, 176));
        renderer.setSeriesPaint(1, new Color(168, 192, 232));
        renderer.setSeriesPaint(2, new Color(248, 120, 8));
        renderer.setSeriesPaint(3, new Color(248, 184, 120));
        renderer.setSeriesPaint(4, new Color(152, 216, 136));
        if (dataLinkBean != null && request != null) {
            renderer.setBaseItemURLGenerator(new CustomURLGeneratorForStackedChart(
                    dataLinkBean.generateURLForChart(request), "", "deviceid"));
        }
        renderer.setBaseToolTipGenerator(new CustomToolTipGeneratorForStacked());
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("StackedColumn3D.e:" + e, e);
    }
    return chart;
}

From source file:com.alcatel_lucent.nz.wnmsreport.chart.TimeSeriesChartCustomiser.java

public void customise(JFreeChart chart, JRChart jasperchart) {

    //LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(); 
    //renderer.setSeriesPaint(1, Color.green); 
    //renderer.setSeriesPaint(4, Color.orange);        

    //chart.setTitle("Customiser has set a new Title"); 

    try {//  w  ww  .j  a va  2  s .  c om

        XYPlot plot = chart.getXYPlot();

        NumberAxis x = (NumberAxis) plot.getDomainAxis();
        //x.setLowerBound(x.getLowerBound()+100);
        x.setUpperBound(x.getUpperBound() + 100);

        NumberAxis y = (NumberAxis) plot.getRangeAxis();
        y.setLowerBound(0);
        y.setUpperBound(100);

    } catch (NullPointerException npe) {
        System.err.println("Error setting chart axis ranges :: " + npe);
    }

}

From source file:net.sourceforge.processdash.ui.web.reports.snippets.EstErrorScatterChart.java

private TruncatedNumberAxis truncAxis(ValueAxis va, double maxValue) {
    NumberAxis axis = (NumberAxis) va;
    double upper = Math.max(100, Math.min(maxValue, axis.getUpperBound()));
    return new TruncatedNumberAxis(va.getLabel(), upper);
}

From source file:eu.choreos.chart.XYChart.java

private JFreeChart createChart(XYDataset dataset, String chartTitle) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "Execution size", // domain axis label
            "Range", // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from  www .j a  va2 s .  com*/

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    return chart;
}

From source file:org.matsim.contrib.analysis.vsp.traveltimedistance.TravelTimeValidationRunner.java

private void writeTravelTimeValidation(String folder, List<CarTrip> trips) {
    BufferedWriter bw = IOUtils.getBufferedWriter(folder + "/validated_trips.csv");
    XYSeriesCollection times = new XYSeriesCollection();
    XYSeriesCollection distances = new XYSeriesCollection();

    XYSeries distancess = new XYSeries("distances", true, true);
    XYSeries timess = new XYSeries("times", true, true);
    times.addSeries(timess);//from w  ww  . ja v  a 2  s.  c om
    distances.addSeries(distancess);
    try {
        bw.append(
                "agent;departureTime;fromX;fromY;toX;toY;traveltimeActual;traveltimeValidated;traveledDistance;validatedDistance");
        for (CarTrip trip : trips) {
            if (trip.getValidatedTravelTime() != null) {
                bw.newLine();
                bw.append(trip.toString());
                timess.add(trip.getActualTravelTime(), trip.getValidatedTravelTime());
                distancess.add(trip.getTravelledDistance(), trip.getValidatedTravelDistance());
            }
        }

        bw.flush();
        bw.close();
        final JFreeChart chart2 = ChartFactory.createScatterPlot("Travel Times", "Simulated travel time [s]",
                "Validated travel time [s]", times);
        final JFreeChart chart = ChartFactory.createScatterPlot("Travel Distances",
                "Simulated travel distance [m]", "Validated travel distance [m]", distances);

        NumberAxis yAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getRangeAxis();
        NumberAxis xAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getDomainAxis();
        NumberAxis yAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis();
        NumberAxis xAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis();
        yAxisd.setUpperBound(xAxisd.getUpperBound());
        yAxis.setUpperBound(xAxis.getUpperBound());
        yAxis.setTickUnit(new NumberTickUnit(500));
        xAxis.setTickUnit(new NumberTickUnit(500));

        XYAnnotation diagonal = new XYLineAnnotation(xAxis.getRange().getLowerBound(),
                yAxis.getRange().getLowerBound(), xAxis.getRange().getUpperBound(),
                yAxis.getRange().getUpperBound());
        ((XYPlot) chart2.getPlot()).addAnnotation(diagonal);

        XYAnnotation diagonald = new XYLineAnnotation(xAxisd.getRange().getLowerBound(),
                yAxisd.getRange().getLowerBound(), xAxisd.getRange().getUpperBound(),
                yAxisd.getRange().getUpperBound());
        ((XYPlot) chart.getPlot()).addAnnotation(diagonald);

        ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveltimes" + ".png"), chart2,
                1500, 1500);
        ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveldistances.png"), chart,
                1500, 1500);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:BaselinePlotGenerator.java

private JFreeChart createChart(String filename, NssBaseline nssBaseline) {

    XYSeries series = new XYSeries("");
    float[] baselineValues = nssBaseline.getBaselineValues();

    // plot subband values
    for (int i = 0; i < baselineValues.length; i++) {
        series.add(i, baselineValues[i]);
    }//from w w  w.  java  2 s . com

    // add a final point at the end with a zero Y value,
    // to force the y axis to display full scale
    series.add(baselineValues.length, 0.0);

    XYDataset data = new XYSeriesCollection(series);

    String title = "SonATA Baseline";
    String xAxisLabel = "Subband";
    String yAxisLabel = "Power";

    JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, data,
            PlotOrientation.VERTICAL, false, // legend 
            true, // tooltips
            false // urls
    );

    String filenameBase = new File(filename).getName();

    String subTitle1 = filenameBase;
    chart.addSubtitle(new TextTitle(subTitle1));

    DecimalFormat freqFormatter = new DecimalFormat("0000.000 MHz  ");
    String freqString = freqFormatter.format(nssBaseline.getCenterFreqMhz());

    DecimalFormat bandwidthFormatter = new DecimalFormat("0.00 MHz  ");
    String bandwidthString = bandwidthFormatter.format(nssBaseline.getBandwidthMhz());

    String subTitle2 = "Center Freq: " + freqString + "     Bandwidth: " + bandwidthString;
    chart.addSubtitle(new TextTitle(subTitle2));

    // move the data off of the axes 
    // by extending the minimum axis value

    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();
    double axisMarginPercent = 0.02;
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent);
    valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent);
    return chart;

}