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

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

Introduction

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

Prototype

public void setLabelFont(Font font) 

Source Link

Document

Sets the font for the axis label and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:com.ouc.cpss.view.ProfitChartBuilder.java

public static JFreeChart createJFreeChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("?", "", "?",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    // ?/* www.  j av a  2 s .com*/
    LegendTitle legendTitle = chart.getLegend(0);
    // 
    legendTitle.setItemFont(new Font("", Font.BOLD, 18));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    // ?
    org.jfree.chart.axis.CategoryAxis categoryAxis = plot.getDomainAxis();
    // 
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 18));

    // 
    categoryAxis.setTickLabelFont(new Font("", Font.BOLD, 12));
    // ?
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    // 
    numberAxis.setLabelFont(new Font("", Font.BOLD, 14));

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//

    CategoryItemRenderer xylineandshaperenderer = plot.getRenderer();
    xylineandshaperenderer.setBaseItemLabelsVisible(true);
    xylineandshaperenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.BASELINE_RIGHT));
    xylineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    return chart;
}

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java

public static void createBoxplot(DefaultBoxAndWhiskerCategoryDataset scatterDataset, PrintStream outStream,
        String title, String xAxisLabel, String yAxisLabel, Font lableFont) throws IOException {

    CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
    xAxis.setLabelFont(lableFont);//from   w  ww  .  ja va 2s  .com
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setTickLabelFont(lableFont);
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setRange(0, 100);
    yAxis.setLabelFont(lableFont);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    renderer.setBaseLegendTextFont(lableFont);
    renderer.setStroke(new BasicStroke(5.0f));

    CategoryPlot plot = new CategoryPlot(scatterDataset, xAxis, yAxis, renderer);
    JFreeChart boxchart = new JFreeChart(title, new Font("Helvetica", Font.BOLD, 40), plot, true);

    // higher scale factor gives higher resolution
    ChartUtilities.writeScaledChartAsPNG(outStream, boxchart, 800, 1000, 3, 3);
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateChartByType(String title, String xLabel, String yLabel, Dataset dataset,
        String outputdir, String type, String filename) throws IOException {
    JFreeChart jChart = null;//  w  ww .  ja va 2s.  c o m
    if ("line".equalsIgnoreCase(type)) {
        jChart = ChartFactory.createLineChart(title, xLabel, yLabel, (CategoryDataset) dataset,
                PlotOrientation.VERTICAL, false, false, false);
    } else if ("bar".equalsIgnoreCase(type)) {
        System.out.println("Setting up jChart");
        jChart = ChartFactory.createBarChart(title, xLabel, yLabel, (CategoryDataset) dataset,
                PlotOrientation.VERTICAL, false, false, false);
        System.out.println("Writing image....");
    } else if ("xyline".equalsIgnoreCase(type)) {
        jChart = ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset,
                PlotOrientation.VERTICAL, false, false, false);
    }

    if ("xyline".equalsIgnoreCase(type)) {

        XYPlot plot = (XYPlot) jChart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
        domain.setAutoRangeIncludesZero(false);

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount());
        //System.out.println("dataset.getRowCount(): " + dataset.getRowCount());

    } else {

        CategoryPlot plot = (CategoryPlot) jChart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));

        CategoryAxis domain = (CategoryAxis) plot.getDomainAxis();
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount());
        //System.out.println("dataset.getRowCount(): " + dataset.getRowCount());

    }

    jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
    ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + filename + ".png"), jChart, 900, 500);
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateChart5(String outputdir, String plotName, String plotData) {
    try {/*w w w .j  a v a 2 s  . co m*/

        CSVReader csv = new CSVReader(new FileReader(plotData));
        List<String[]> rawdata = csv.readAll();
        double[][] dataCht = new double[2][rawdata.size() - 1];
        for (int i = 1; i < rawdata.size(); i++) {
            String[] row = rawdata.get(i);
            dataCht[0][i - 1] = Double.parseDouble(row[0]);
            dataCht[1][i - 1] = Double.parseDouble(row[1]);
        }

        DefaultXYDataset dataset = new DefaultXYDataset();
        dataset.addSeries("", dataCht);

        System.out.println("Setting up jChart for " + plotName);
        //generateChartByType(plotName, plotName, "f("+plotName+")", null, outputdir, "xyline", plotName);
        JFreeChart jChart = ChartFactory.createXYLineChart(plotName, plotName, "f(" + plotName + ")", dataset,
                PlotOrientation.VERTICAL, false, false, false);

        jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        XYPlot plot = (XYPlot) jChart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + ".png"), jChart, 500, 500);
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + "_thumb.png"), jChart, 210,
                140);

    } catch (Exception e) {
        System.out.println("Unable to generate charts 2 and 3:");
        e.printStackTrace(System.out);
    }
}

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 w w . j  a v a 2  s  .  c  om*/
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:net.sf.profiler4j.console.AllocDiffPanel.java

public AllocDiffPanel(int maxAgeMillis) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAgeMillis);

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);

    NumberAxis numberAxis = new NumberAxis("Allocs/Sec");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);/*w  w  w  .  jav a2s .c  o  m*/
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM",
            new Font("SansSerif", Font.PLAIN, 18), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:org.jfree.chart.demo.IntervalBarChartDemo1.java

/**
 * Creates a new demo.//ww w  .  jav  a  2 s  .  c o m
 */
public IntervalBarChartDemo1() {

    DefaultIntervalCategoryDataset data = null;
    final double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    final double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    data = new DefaultIntervalCategoryDataset(lows, highs);
    data.setCategoryKeys(CATEGORIES);

    final String title = "Strategie Sicherheit";
    final String xTitle = "Zeitraum (in Jahren)";
    final String yTitle = "Performance";
    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.40);
    final DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    final IntervalBarRenderer renderer = new IntervalBarRenderer();
    renderer.setSeriesPaint(0, new Color(51, 102, 153));
    //        renderer.setLabelGenerator(new IntervalCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelPaint(Color.white);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(p);

    final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.white);
    plot.setOrientation(PlotOrientation.VERTICAL);

    this.chart = new JFreeChart(title, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);
}

From source file:net.sf.profiler4j.console.MemoryPlotPanel.java

public MemoryPlotPanel(int maxAge, String title) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Committed Memory", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAge);
    usedSeries = new TimeSeries("Used Memory", Millisecond.class);
    usedSeries.setMaximumItemAge(maxAge);
    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);
    seriesCollection.addSeries(usedSeries);

    NumberAxis numberAxis = new NumberAxis("Memory (KB)");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);//from w  ww .j  av  a 2s. co m
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateCharts123(String outputdir) {
    try {//w  w  w. j av  a2 s  . c  om
        IniReader ir = new IniReader(outputdir + "/gdm_params.txt");
        double intercept = ir.getDoubleValue("GDMODEL", "Intercept");

        // 1. read the ObservedVsPredicted.csv file
        System.out.println("Loading csv data");
        CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv"));
        List<String[]> rawdata = csv.readAll();
        double[][] dataCht1 = new double[2][rawdata.size() - 1];
        double[][] dataCht2 = new double[2][rawdata.size() - 1];

        // for Chart 1: obs count
        int[] obscount = new int[11];
        for (int i = 0; i < obscount.length; i++) {
            obscount[i] = 0;
        }

        System.out.println("populating data");
        for (int i = 1; i < rawdata.size(); i++) {
            String[] row = rawdata.get(i);
            double obs = Double.parseDouble(row[4]);
            dataCht1[0][i - 1] = Double.parseDouble(row[6]);
            dataCht1[1][i - 1] = obs;

            dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept;
            dataCht2[1][i - 1] = obs;

            int obc = (int) Math.round(obs * 10);
            obscount[obc]++;
        }

        DefaultXYDataset dataset1 = new DefaultXYDataset();
        dataset1.addSeries("", dataCht1);

        DefaultXYDataset dataset2 = new DefaultXYDataset();
        dataset2.addSeries("", dataCht2);

        DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();
        for (int i = 0; i < obscount.length; i++) {
            String col = "0." + i + "-0." + (i + 1);
            if (i == 10) {
                col = "0.9-1.0";
            }
            dataset3.addValue(obscount[i] + 100, "col", col);
        }
        generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs",
                dataset3, outputdir, "bar", "resphist");

        XYDotRenderer renderer = new XYDotRenderer();
        //Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
        //renderer.setSeriesShape(0, cross);
        renderer.setDotWidth(3);
        renderer.setDotHeight(3);
        renderer.setSeriesPaint(0, Color.BLACK);

        JFreeChart jChart1 = ChartFactory.createScatterPlot(
                "Observed versus predicted compositional dissimilarity",
                "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1,
                PlotOrientation.VERTICAL, false, false, false);
        jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        XYPlot plot = (XYPlot) jChart1.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        double dMinPred = domain.getRange().getLowerBound();
        double dMaxPred = domain.getRange().getUpperBound();

        double dMinObs = range.getRange().getLowerBound();
        double dMaxObs = range.getRange().getUpperBound();

        System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred);

        int regressionLineSegs = 10;
        double dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        double[][] dataReg1 = new double[2][regressionLineSegs + 1];
        DefaultXYDataset dsReg1 = new DefaultXYDataset();
        int i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = d;
        }
        dsReg1.addSeries("", dataReg1);
        XYSplineRenderer regressionRenderer = new XYSplineRenderer();
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400);

        // For chart 3
        JFreeChart jChart2 = ChartFactory.createScatterPlot(
                "Observed compositional dissimilarity vs predicted ecological distance",
                "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2,
                PlotOrientation.VERTICAL, false, false, false);
        jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        plot = (XYPlot) jChart2.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        dMinPred = domain.getRange().getLowerBound();
        dMaxPred = domain.getRange().getUpperBound();

        dMinObs = range.getRange().getLowerBound();
        dMaxObs = range.getRange().getUpperBound();

        System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred);

        regressionLineSegs = 10;
        dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        dataReg1 = new double[2][regressionLineSegs + 1];
        dsReg1 = new DefaultXYDataset();
        i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = (1.0 - Math.exp(-d));
        }
        dsReg1.addSeries("", dataReg1);
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400);

    } catch (Exception e) {
        System.out.println("Unable to generate charts 2 and 3:");
        e.printStackTrace(System.out);
    }
}

From source file:org.jfree.chart.demo.OverlaidCategoryChartDemo.java

/**
 * Creates a new demo./*from w ww  .  j a  v a 2 s. co m*/
 *
 * @param title  the frame title.
 */
public OverlaidCategoryChartDemo(String title) {

    super(title);
    DefaultIntervalCategoryDataset barData = null;
    double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    barData = new DefaultIntervalCategoryDataset(lows, highs);

    double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } };
    CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals);

    double[][] lineVals = new double[4][5];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            lineVals[i][j] = (Math.random() * 0.56) - 0.18;
        }
    }
    CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals);

    String ctitle = "Strategie Sicherheit";
    String xTitle = "Zeitraum (in Jahren)";
    String yTitle = "Performance";
    CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.4);
    DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    IntervalBarRenderer barRenderer = new IntervalBarRenderer();
    barRenderer.setItemLabelsVisible(Boolean.TRUE);

    CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.black);

    LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES);
    dotRenderer.setItemLabelsVisible(Boolean.TRUE);

    plot.setSecondaryDataset(0, dotData);
    plot.setSecondaryRenderer(0, dotRenderer);

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES);
    plot.setSecondaryDataset(1, lineData);
    plot.setSecondaryRenderer(1, lineRenderer);

    this.chart = new JFreeChart(ctitle, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}