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

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

Introduction

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

Prototype

public void setAxisLineVisible(boolean visible) 

Source Link

Document

Sets a flag that controls whether or not the axis line is visible and sends an AxisChangeEvent to all registered listeners.

Usage

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;//from w  w w.j a  va2s  .  c om
    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 ww.java 2  s  . com*/

        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.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.
 *///from  w w w  .j  av  a 2  s  .com
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: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.tolven.analysis.bean.PercentTimeSeriesBean.java

private JFreeChart getChart(String dataSeriesTitle, String targetSeriesTitle, List<MenuData> snapshots,
        Date fromDate, Date toDate, Class<?> intervalUnitClass) {
    TimeSeries dataTimeSeries = new TimeSeries(dataSeriesTitle);
    TimeSeries targetTimeSeries = null;/*from w  w w  .j  a  v  a  2 s.co  m*/
    if (targetSeriesTitle != null) {
        targetTimeSeries = new TimeSeries(targetSeriesTitle);
    }
    for (MenuData snapshot : snapshots) {
        Date snapshotDate = snapshot.getDate01();
        long nSnapshotresultsNumerator = snapshot.getLongField("normCount");
        long nSnapshotresultsDenominator = snapshot.getLongField("allCount");
        Double value = null;
        if (nSnapshotresultsDenominator == 0) {
            value = 0d;
        } else {
            value = 1d * nSnapshotresultsNumerator / nSnapshotresultsDenominator;
        }
        RegularTimePeriod regTimePeriod = RegularTimePeriod.createInstance(intervalUnitClass, snapshotDate,
                TimeZone.getDefault());
        dataTimeSeries.addOrUpdate(regTimePeriod, value);
        if (targetTimeSeries != null) {
            Double targetPercent = snapshot.getDoubleField("targetPercent") / 100;
            targetTimeSeries.addOrUpdate(regTimePeriod, targetPercent);
        }
    }
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();
    timeSeriesCollection.addSeries(dataTimeSeries);
    if (targetTimeSeries != null) {
        timeSeriesCollection.addSeries(targetTimeSeries);
    }
    XYDataset xyDataset = (XYDataset) timeSeriesCollection;
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            null, // x-axis label
            null, // y-axis label
            xyDataset, // data
            true, // create legend?
            false, // generate tooltips?
            false // generate URLs?
    );
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setDomainGridlinesVisible(false);
    XYItemRenderer r = plot.getRenderer();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 6, 6));
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setSeriesShape(1, new Rectangle2D.Double(-3, -3, 6, 6));
    renderer.setSeriesPaint(1, Color.RED);
    NumberAxis vaxis = (NumberAxis) plot.getRangeAxis();
    vaxis.setAutoRange(true);
    vaxis.setAxisLineVisible(true);
    vaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    vaxis.setTickMarksVisible(true);
    DateAxis daxis = (DateAxis) plot.getDomainAxis();
    daxis.setRange(fromDate, toDate);
    if (intervalUnitClass == Month.class) {
        DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
        dateFormatSymbols
                .setShortMonths(new String[] { "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D" });
        daxis.setDateFormatOverride(new SimpleDateFormat("MMM", dateFormatSymbols));
    }
    return chart;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createStepAreaChart(XYDataset dataset, XYItemLabelGenerator labelGenerator) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }/*from w w  w . j  a  v  a  2 s  .  com*/

    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(UIConstants.INTEL_BACKGROUND_GRAY);
    // xyplot.setOutlinePaint(null);
    XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA) {

        @Override
        public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
                PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
            setShapesVisible(item == dataset.getItemCount(series) - 1);
            super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                    crosshairState, pass);
        }

    };
    xysteparearenderer.setDataBoundsIncludesVisibleSeriesOnly(false);
    xysteparearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xysteparearenderer.setDefaultEntityRadius(6);
    xysteparearenderer.setShapesFilled(true);
    xyplot.setRenderer(xysteparearenderer);

    if (labelGenerator != null) {
        xysteparearenderer.setBaseItemLabelGenerator(labelGenerator);
    }
    xysteparearenderer.setSeriesPaint(0, UIConstants.INTEL_GREEN);
    xyplot.setOutlinePaint(UIConstants.INTEL_DARK_GRAY);
    xyplot.setDomainGridlinePaint(UIConstants.INTEL_DARK_GRAY);
    xyplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);

    xyplot.getDomainAxis().setVisible(false);

    NumberAxis axis = (NumberAxis) xyplot.getRangeAxis();
    axis.setRangeType(RangeType.POSITIVE);
    axis.setAxisLineVisible(false);

    return jfreechart;
}

From source file:web.diva.server.unused.ProfilePlotGenerator.java

/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings./*from w  ww . j  a v a  2 s  .  c  o m*/
 *
 * @param title the chart title (<code>null</code> permitted).
 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted).
 * @param dataset the dataset for the chart (<code>null</code> permitted).
 * @param orientation the plot orientation (horizontal or vertical)
 * (<code>null</code> NOT permitted).
 * @param legend a flag specifying whether or not a legend is required.
 * @param tooltips configure chart to generate tool tips?
 * @param urls configure chart to generate URLs?
 *
 * @return The chart.
 */
private JFreeChart createXYLineChart(String title, String[] columnIds, XYDataset dataset,
        PlotOrientation orientation, boolean legend, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    Font f = new Font("ARIAL", 1, 7);
    //        NumberAxis xAxis = new NumberAxis(xAxisLabel);
    //        xAxis.setAutoRangeIncludesZero(false);
    SymbolAxis xAxis = new SymbolAxis("", columnIds);
    xAxis.setAxisLineVisible(false);
    xAxis.setGridBandsVisible(false);
    xAxis.setVerticalTickLabels(true);
    xAxis.setVisible(true);

    xAxis.setTickLabelPaint(shadowColor);
    xAxis.setTickLabelFont(f);
    xAxis.setFixedDimension(51.0);

    boolean auto = xAxis.getAutoRangeIncludesZero();
    xAxis.setAutoRangeIncludesZero(true ^ auto);
    xAxis.setTickUnit(new NumberTickUnit(1));
    xAxis.setRange(0, columnIds.length);
    //        NumberAxis yAxis = new NumberAxis(yAxisLabel);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(true ^ auto);
    yAxis.setAxisLineVisible(false);
    yAxis.setTickLabelFont(f);
    yAxis.setTickLabelPaint(Color.BLUE);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseShapesVisible(false);
    renderer.setPaint(shadowColor);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);

    plot.setBackgroundPaint(Color.WHITE);

    plot.setDomainGridlinePaint(shadowColor);
    plot.setRangeGridlinePaint(shadowColor);
    plot.setOutlinePaint(Color.BLUE);
    //        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    //        plot.setRenderer(renderer);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);

    plot.setDomainAxis(xAxis);

    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}

From source file:com.bt.aloha.sipstone.GenGraph.java

private JFreeChart createCombinedChart() {
    XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond();
    XYDataset xydataset = xydatasetArray[0];
    final XYDataset percXydataset = xydatasetArray[1];
    JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = new NumberAxis("Avg. Response Time");
    numberaxis.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis);//from w w  w .ja  va  2 s. c o  m
    xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime());
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setShapesFilled(true);
    }
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer1.setBaseShapesVisible(true);
    xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xyplot.setRenderer(1, xylineandshaperenderer1);
    NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis();
    timeaxis.setAutoRange(true);
    timeaxis.setAxisLineVisible(true);
    LegendTitle legendtitle = new LegendTitle(xyitemrenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));

    XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer();
    xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset));
    xyrenderer.setBaseItemLabelsVisible(true);

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:edu.ku.brc.specify.toycode.BugParse.java

/**
 * @param lines//from   w  w w .j  av a2  s. c o m
 */
protected void createChart(final List<String> lines, final String engineer) {

    int[] mins = new int[lines.size() - 1];
    for (int index = 1; index < lines.size(); index++) {
        String line = lines.get(index);
        String[] values = StringUtils.splitPreserveAllTokens(line, ",");
        int inx = 0;
        while (inx < values.length && values[inx].equals("0")) {
            inx++;
        }
        mins[index - 1] = inx < values.length ? inx : Integer.MAX_VALUE;
        System.err.println(mins[index - 1]);
    }

    int startInx = Integer.MAX_VALUE;
    for (int min : mins) {
        startInx = Math.min(startInx, min);
        System.out.println(min + "  " + startInx);
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String[] headers = StringUtils.split(lines.get(0), ",");
    int len = headers.length - startInx;
    System.out.println(headers.length + "  " + len);
    List<double[]> valArray = new Vector<double[]>();

    for (int i = 1; i < lines.size(); i++) {
        String[] values = StringUtils.splitPreserveAllTokens(lines.get(i), ",");
        double[] vals = new double[len];
        int inx = 0;
        double prev = -1;
        for (int j = startInx; j < headers.length; j++) {
            if (StringUtils.isNotEmpty(values[j])) {
                prev = Double.parseDouble(values[j]);
                vals[inx++] = prev;
            } else {
                vals[inx++] = 0.0;
            }
        }
        valArray.add(vals);
    }

    double[] vals = valArray.get(0);
    for (int i = 0; i < vals.length; i++) {
        dataset.addValue(vals[i], "Bugs", headers[i + startInx]);
    }
    vals = valArray.get(1);
    for (int i = 0; i < vals.length; i++) {
        dataset.addValue(vals[i], "Resolved", headers[i + startInx]);
    }

    vals = valArray.get(2);
    for (int i = 0; i < vals.length; i++) {
        dataset.addValue(vals[i], "Open", headers[i + startInx]);
    }

    JFreeChart chart = ChartFactory.createLineChart("Bugs - " + engineer, "Time", "Bugs", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //plot.setBackgroundPaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAxisLineVisible(true);

    CategoryAxis catAxis = plot.getDomainAxis();
    catAxis.setAxisLineVisible(true);
    catAxis.setTickMarksVisible(true);

    ChartFrame frame = new ChartFrame("", chart, false);
    frame.setBackground(Color.WHITE);
    frame.setSize(500, 500);
    frame.setVisible(true);
}

From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio",
            "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9

    // GRIDLINES/*from w ww.  ja v  a 2  s. c  o m*/
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    // AXIS
    double maxHetzy = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxHetzy < dataset.getXValue(0, i)) {
            maxHetzy = dataset.getXValue(0, i);
        }
    }
    NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis();
    hetzyAxis.setAutoRangeIncludesZero(true);
    hetzyAxis.setAxisLineVisible(true);
    hetzyAxis.setTickLabelsVisible(true);
    hetzyAxis.setTickMarksVisible(true);
    hetzyAxis.setRange(0, maxHetzy * 1.1);

    double maxMissrat = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxMissrat < dataset.getYValue(0, i)) {
            maxMissrat = dataset.getYValue(0, i);
        }
    }
    NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis();
    missratAxis.setAutoRangeIncludesZero(true);
    missratAxis.setAxisLineVisible(true);
    missratAxis.setTickLabelsVisible(true);
    missratAxis.setTickMarksVisible(true);
    missratAxis.setRange(0, maxMissrat * 1.1);

    // Add significance Threshold to subplot
    final Marker missingThresholdLine = new ValueMarker(missingThreshold);
    missingThresholdLine.setPaint(Color.blue);

    final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold);
    hetzyThresholdLine.setPaint(Color.blue);

    // Add legend to hetzyThreshold
    hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold);
    missingThresholdLine.setLabel("missing. threshold = " + missingThreshold);
    hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO
    plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO

    // Marker label if below hetzyThreshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator();

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}