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

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

Introduction

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

Prototype

public static TickUnitSource createStandardTickUnits() 

Source Link

Document

Creates the standard tick units.

Usage

From source file:io.narayana.perf.product.BarChart.java

public JFreeChart generateChart(String title, String xaxisLabel, String yaxisLabel) {
    JFreeChart chart = ChartFactory.createBarChart(title, xaxisLabel, yaxisLabel, dataset,
            PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = chart.getCategoryPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);

    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();

    for (int i = 0; i < dataset.getRowCount(); i++) {
        Color color = i < COLORS.length ? COLORS[i] : COLORS[0];
        renderer.setSeriesPaint(i, color);
    }/*  ww  w  .j  a  v a2  s  .c  o  m*/

    return chart;
}

From source file:wsattacker.plugin.dos.dosExtension.chart.ChartObject.java

public JFreeChart createOverlaidChart() {

    // ----------------------------
    // Data and X-Y-Axis - Response Time Testprobes
    // - Y-Achse 0
    final DateAxis yAxis = new DateAxis("Time");
    yAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    // - X-Achse 0
    final NumberAxis xAxis0 = new NumberAxis("Response Time in ms");
    xAxis0.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // xAxis0.setTickUnit( new NumberTickUnit(1) );
    // - dataset/*  ww w.j  a v  a  2  s  .co  m*/
    // - renderer
    final XYDataset dataResponseTimeProbes = createDatasetResponseTime("testprobe");
    final XYLineAndShapeRenderer rendererResponseTimeProbes = new XYLineAndShapeRenderer(); // StandardXYItemRenderer();
                                                                                            // ->
                                                                                            // should
                                                                                            // not
                                                                                            // be
                                                                                            // used
    rendererResponseTimeProbes.setSeriesPaint(0, Color.blue);
    rendererResponseTimeProbes.setSeriesShape(0, new Ellipse2D.Double(-1.5, -1.5, 3.0, 3.0));
    rendererResponseTimeProbes.setSeriesLinesVisible(0, true);
    rendererResponseTimeProbes.setSeriesShapesVisible(0, true);
    rendererResponseTimeProbes.setUseOutlinePaint(false);
    rendererResponseTimeProbes.setSeriesOutlinePaint(0, Color.black);
    rendererResponseTimeProbes.setUseFillPaint(true);
    rendererResponseTimeProbes.setSeriesFillPaint(0, Color.blue);

    // ----------------------------
    // NEW XYPlot (new "Data and X-Y-Axis" from above added as default)
    final XYPlot plot = new XYPlot(dataResponseTimeProbes, yAxis, xAxis0, rendererResponseTimeProbes);

    // ----------------------------
    // Data and Axis 1 - Response time UNtampered
    // - Dataset
    // - Renderer.
    // - Dataset zu X-Axis 0 mappen
    final XYDataset dataResponseTimeUntampered = createDatasetResponseTime("untampered");
    final XYLineAndShapeRenderer rendererResponseTimeUntampered = new XYLineAndShapeRenderer(); // StandardXYItemRenderer();
                                                                                                // ->
                                                                                                // should
                                                                                                // not
                                                                                                // be
                                                                                                // used
    rendererResponseTimeUntampered.setSeriesPaint(0, new Color(0, 161, 4));
    rendererResponseTimeUntampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));
    rendererResponseTimeUntampered.setUseFillPaint(true);
    rendererResponseTimeUntampered.setSeriesFillPaint(0, Color.white);
    rendererResponseTimeUntampered.setUseOutlinePaint(false);
    rendererResponseTimeUntampered.setSeriesOutlinePaint(0, Color.black);
    rendererResponseTimeUntampered.setSeriesToolTipGenerator(0,
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(2, dataResponseTimeUntampered);
    plot.setRenderer(2, rendererResponseTimeUntampered);
    // plot.mapDatasetToRangeAxis(0, 1);

    // ----------------------------
    // Data and Axis - Response time tampered
    // - Dataset
    // - Renderer
    // - Dataset zu X-Axis 2 mappen
    final XYDataset dataResponseTimeTampered = createDatasetResponseTime("tampered");
    XYLineAndShapeRenderer rendererResponseTimeTampered = new XYLineAndShapeRenderer(); // XYSplineRenderer();
    rendererResponseTimeTampered.setSeriesPaint(0, new Color(189, 0, 0));
    rendererResponseTimeTampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));// (-2.5, -2.5, 6.0,
                                                                                           // 6.0) );
    rendererResponseTimeTampered.setUseFillPaint(true);
    rendererResponseTimeTampered.setSeriesFillPaint(0, Color.white);
    rendererResponseTimeTampered.setUseOutlinePaint(false);
    rendererResponseTimeTampered.setSeriesOutlinePaint(0, Color.black);
    plot.setDataset(3, dataResponseTimeTampered);
    plot.setRenderer(3, rendererResponseTimeTampered);
    // plot.mapDatasetToRangeAxis(0, 2);

    // ----------------------------
    // Data and X-Axis - Number Requests UNtampered
    // - X-Axis Number Requests
    final NumberAxis xAxis1 = new NumberAxis(
            "Number Requests Per Interval (" + (model.getIntervalLengthReport() / 1000) + " sec)");
    xAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // xAxis1.setTickUnit( new NumberTickUnit(2) );
    plot.setRangeAxis(1, xAxis1);
    // - Dataset
    // - Renderer
    final IntervalXYDataset dataNumberRequestsUntampered = createDatasetNumberRequestsUntampered();
    final XYBarRenderer rendererNumberRequestsUntampered = new XYBarRenderer(0.2);
    rendererNumberRequestsUntampered.setShadowVisible(false);
    rendererNumberRequestsUntampered.setBarPainter(new StandardXYBarPainter());
    rendererNumberRequestsUntampered.setSeriesPaint(0, new Color(128, 255, 128));
    plot.setDataset(4, dataNumberRequestsUntampered);
    plot.setRenderer(4, rendererNumberRequestsUntampered);
    plot.mapDatasetToRangeAxis(4, 1);

    // -------------------------------
    // Data - Number Requests tampered
    // - Dataset
    // - Renderer
    final IntervalXYDataset dataNumberRequestsTampered = createDatasetNumberRequestsTampered();
    final XYBarRenderer rendererBarNumberRequestsTampered = new XYBarRenderer(0.2);
    rendererBarNumberRequestsTampered.setShadowVisible(false);
    rendererBarNumberRequestsTampered.setBarPainter(new StandardXYBarPainter());
    rendererBarNumberRequestsTampered.setSeriesPaint(0, new Color(255, 148, 148));
    plot.setDataset(5, dataNumberRequestsTampered);
    plot.setRenderer(5, rendererBarNumberRequestsTampered);
    plot.mapDatasetToRangeAxis(5, 1);

    // -------------------------
    // Other formating stuff
    // - add annotations
    // final double x = new Day(9, SerialDate.MARCH,
    // 2002).getMiddleMillisecond();
    // final XYTextAnnotation annotation = new
    // XYTextAnnotation("Anmerkung zu Datenpunkt", x, 1000.0);
    // annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    // plot.addAnnotation(annotation);

    // -------------------------
    // Create custom LegendTitles
    // Legend Row 1
    LegendTitle legendL1 = new LegendTitle(plot.getRenderer(0));
    legendL1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL1.setBorder(0, 0, 0, 0);
    LegendTitle legendR1 = new LegendTitle(plot.getRenderer(4));
    legendR1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendR1.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.setBorder(0, 0, 0, 0);
    blockcontainer.add(legendL1, RectangleEdge.LEFT);
    blockcontainer.add(legendR1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle1 = new CompositeTitle(blockcontainer);
    compositetitle1.setPosition(RectangleEdge.BOTTOM);
    // Legend Row 2
    LegendTitle legendL2 = new LegendTitle(plot.getRenderer(2));
    legendL2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL2.setBorder(0, 0, 0, 0);
    LegendTitle legendR2 = new LegendTitle(plot.getRenderer(5));
    legendR2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendR2.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer2 = new BlockContainer(new BorderArrangement());
    blockcontainer2.setBorder(0, 0, 0, 0);
    blockcontainer2.add(legendL2, RectangleEdge.LEFT);
    blockcontainer2.add(legendR2, RectangleEdge.RIGHT);
    blockcontainer2.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle2 = new CompositeTitle(blockcontainer2);
    compositetitle2.setPosition(RectangleEdge.BOTTOM);
    // Legend Row 3
    LegendTitle legendL3 = new LegendTitle(plot.getRenderer(3));
    legendL3.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendL3.setBorder(0, 0, 0, 0);
    BlockContainer blockcontainer3 = new BlockContainer(new BorderArrangement());
    blockcontainer3.setBorder(0, 0, 0, 0);
    blockcontainer3.add(legendL3, RectangleEdge.LEFT);
    blockcontainer3.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle3 = new CompositeTitle(blockcontainer3);
    compositetitle3.setPosition(RectangleEdge.BOTTOM);

    // -------------------------
    // create Chart
    // - return a new chart containing the overlaid plot...
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart jFreeChart = new JFreeChart(model.getAttackName() + " - Response Time Plot", // Roundtrip Time Plot
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    // Add new legend boxes + format
    jFreeChart.addSubtitle(compositetitle1);
    jFreeChart.addSubtitle(compositetitle2);
    jFreeChart.addSubtitle(compositetitle3);

    // Surpress old Legends
    LegendTitle legendee2 = jFreeChart.getLegend(0);
    legendee2.setVisible(false);

    return jFreeChart;
}

From source file:org.jgrasstools.gears.utils.images.LineChartGenerator.java

/**
 * Creates the chart image and dumps it to file.
 * /*from  w ww  . j  a  va2  s  .  c  om*/
 * @param chartFile the file to which to write to.
 * @param autoRange flag to define if to auto define the range from the bounds.
 * @param withLegend flag to define the legend presence.
 * @param imageWidth the output image width (if -1 default is used).
 * @param imageHeight the output image height (if -1 default is used).
 * @throws IOException
 */
@SuppressWarnings("nls")
public void dumpChart(File chartFile, boolean autoRange, boolean withLegend, int imageWidth, int imageHeight)
        throws IOException {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, collection,
            PlotOrientation.VERTICAL, withLegend, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    // plot.setDomainPannable(true);
    // plot.setRangePannable(true);

    // plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (autoRange) {
        double delta = (max - min) * 0.1;
        yAxis.setRange(min - delta, max + delta);
        yAxis.setMinorTickCount(4);
        yAxis.setMinorTickMarksVisible(true);
    }
    // ValueAxis xAxis = plot.getDomainAxis();
    // xAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));

    // XYItemRenderer renderer = plot.getRenderer();
    // renderer.setDrawBarOutline(false);
    // // flat bars look best...
    // renderer.setBarPainter(new StandardXYBarPainter());
    // renderer.setShadowVisible(false);

    if (!chartFile.getName().endsWith(".png")) {
        chartFile = FileUtilities.substituteExtention(chartFile, "png");
    }
    if (imageWidth == -1) {
        imageWidth = IMAGEWIDTH;
    }
    if (imageHeight == -1) {
        imageHeight = IMAGEHEIGHT;
    }
    BufferedImage bufferedImage = chart.createBufferedImage(imageWidth, imageHeight);
    ImageIO.write(bufferedImage, "png", chartFile);
}

From source file:slash.navigation.converter.gui.elevationview.ElevationView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();/*from   w  w  w . ja  v  a 2 s  .c om*/
    plot.setForegroundAlpha(0.65F);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{2}m @ {1} Km",
            NumberFormat.getIntegerInstance(), NumberFormat.getIntegerInstance()));
    return plot;
}

From source file:org.codehaus.mojo.chronos.chart.HistoryChartGenerator.java

public final void createGcChart(HistoricSamples samples, String dataId) throws IOException {
    XYPlot xyplot1 = newPlot(samples.getGcRatio(dataId), "chronos.label.gc.ratio", true);
    xyplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    xyplot1.getRenderer().setSeriesPaint(0, Color.GREEN);
    xyplot1.getRangeAxis().setStandardTickUnits(NumberAxis.createStandardTickUnits());

    XYPlot xyplot2 = newPlot(samples.getKbCollectedPrSecond(dataId), "chronos.label.gc.kbpersec", true);
    xyplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    xyplot2.getRenderer().setSeriesPaint(0, Color.GRAY);
    xyplot2.getRangeAxis().setStandardTickUnits(NumberAxis.createStandardTickUnits());

    String timeLabel = bundle.getString("chronos.label.gc.historytime");
    DateAxis timeAxis = ChartUtil.createTimeAxis(timeLabel, new SimpleDateFormat());
    XYPlot combinedPlot = ChartUtil.createCombinedPlot(timeAxis, xyplot1, xyplot2);
    // xyplot1.setDomainAxis( timeAxis );
    // XYPlot combinedPlot = xyplot1;
    JFreeChart chart = new JFreeChart(bundle.getString("chronos.label.gc"), combinedPlot);
    renderer.renderChart("history-gc-" + dataId, chart);
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.clusterchart.SimpleCluster.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createBubbleChart(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            legend, true, false);/*from  w ww  .j  av a2s .  co m*/

    /*Font font = new Font("Tahoma", Font.BOLD, titleDimension);
    TextTitle title = new TextTitle(name, font);
    chart.setTitle(title);*/

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    Color colorSubInvisibleTitle = Color.decode("#FFFFFF");
    StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle);
    TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle);
    chart.addSubtitle(subsubTitle);

    chart.setBackgroundPaint(color);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    //plot.setForegroundAlpha(0.50f);
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();

    //define colors
    int seriesN = dataset.getSeriesCount();
    if (colorMap != null) {
        boolean isSerieSel = true;
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            String tmpName = serieName.replaceAll(" ", "");
            tmpName = tmpName.replace('.', ' ').trim();
            if (serie_selected != null && serie_selected.size() > 0) {
                String serieSel = serie_selected.get(tmpName).toString();
                isSerieSel = (serieSel.equalsIgnoreCase("TRUE") || serieSel.equalsIgnoreCase("YES")
                        || serieSel.equalsIgnoreCase("1")) ? true : false;
                serieName = tmpName;
            }

            if (color != null && isSerieSel) {
                Color color = (Color) colorMap.get(serieName);
                renderer.setSeriesPaint(i, color);
            } else {
                Color color = new Color(Integer.decode(defaultColor).intValue());
                renderer.setSeriesPaint(i, color);
            }
        }
    }

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setAutoRange(true);
    domainAxis.setRange(yMin, yMax);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());

    //rangeAxis.setAutoRange(true);
    rangeAxis.setRange(xMin, xMax);

    TickUnits units = null;
    if (decimalXValues == false)
        units = (TickUnits) NumberAxis.createIntegerTickUnits();
    else
        units = (TickUnits) NumberAxis.createStandardTickUnits();
    rangeAxis.setStandardTickUnits(units);

    TickUnits domainUnits = null;
    if (decimalYValues == false)
        domainUnits = (TickUnits) NumberAxis.createIntegerTickUnits();
    else
        domainUnits = (TickUnits) NumberAxis.createStandardTickUnits();
    domainAxis.setStandardTickUnits(domainUnits);

    rangeAxis.setLowerMargin(1.0);
    rangeAxis.setUpperMargin(1.0);

    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());

    domainAxis.setLowerMargin(1.0);
    domainAxis.setUpperMargin(1.0);
    //DecimalFormat format=(new DecimalFormat("0"));
    //rangeAxis.setNumberFormatOverride(format);

    if (legend == true)
        drawLegend(chart);

    return chart;
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.KaplanMeierPlot.java

private void createChart(XYDataset dataset) {
    //Create the chart, dropping in the data set
    JFreeChart chart = ChartFactory.createXYLineChart("", "Days in Study", "Probability of Survival", dataset,
            PlotOrientation.VERTICAL, false, //legend
            true, //tooltips
            false//urls
    );/*from   w  w w  . j a va 2  s. c om*/
    LegendTitle legend = chart.getLegend();
    XYPlot plot = (XYPlot) chart.getPlot();
    /********************************************************
     * IMPORTANT:
     * Ideally I would create the actual Renderer settings for
     * the at the time I start to march through the 
     * KaplanMeierPlotPointSeriesSets, adding them to the actual
     * Data Set that is going to be going into the Chart plotter.
     * But you have no idea how they are going to be sitting in
     * the Plot dataset so there is no guarantee that setting the
     * renderer based on a supposed index will actually work. In fact
     * it didn't work when I wrote this.
     * 
     */
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < finalDataCollection.getSeriesCount(); i++) {
        KaplanMeierPlotPointSeries kmSeries = (KaplanMeierPlotPointSeries) finalDataCollection.getSeries(i);
        if (kmSeries.getType() == SeriesType.CENSOR) {
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, true);
        } else if (kmSeries.getType() == SeriesType.PROBABILITY) {
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesVisible(i, false);

        } else {
            //don't show this set as it is not a known type
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, false);
        }
        renderer.setSeriesPaint(i, getKMSetColor(kmSeries.getKey(), kmSeries.getType()), true);
    }

    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    plot.setRenderer(renderer);
    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    rangeAxis.setAutoRange(true);
    rangeAxis.setRange(0.0, 1.0);
    kmChart = 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.
 *//*w ww  .j  a va2 s . c om*/
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:gov.nih.nci.caintegrator.plots.kaplanmeier.JFreeChartIKMPlottermpl.java

public JFreeChart createKMPlot(Collection<GroupCoordinates> groupsToBePlotted, String title, String xAxisLabel,
        String yAxisLabel) {/*  w  w w . ja  va2s .c om*/
    List<KMPlotPointSeriesSet> kmPlotSets = new ArrayList<KMPlotPointSeriesSet>(
            convertToKaplanMeierPlotPointSeriesSet(groupsToBePlotted));

    XYSeriesCollection finalDataCollection = new XYSeriesCollection();
    /*  Repackage all the datasets to go into the XYSeriesCollection */
    for (KMPlotPointSeriesSet dataSet : kmPlotSets) {
        finalDataCollection.addSeries(dataSet.getCensorPlotPoints());
        finalDataCollection.addSeries(dataSet.getProbabilityPlotPoints());

    }

    JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, finalDataCollection,
            PlotOrientation.VERTICAL, true, //legend
            true, //tooltips
            false//urls
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    /*
     * Ideally the actual Renderer settings should have been created
     * at the survivalLength of iterating KaplanMeierPlotPointSeriesSets, adding them to the actual
     * Data Set that is going to be going into the Chart plotter.  But you have no idea how
     * they are going to be sitting in the Plot dataset so there is no guarantee that setting the
     * renderer based on a supposed index will actually work. In fact
     */

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < finalDataCollection.getSeriesCount(); i++) {
        KMPlotPointSeries kmSeries = (KMPlotPointSeries) finalDataCollection.getSeries(i);

        if (kmSeries.getType() == KMPlotPointSeries.SeriesType.CENSOR) {
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, true);
            renderer.setSeriesShape(i, getCensorShape());
        } else if (kmSeries.getType() == KMPlotPointSeries.SeriesType.PROBABILITY) {
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesVisible(i, false);

        } else {
            //don't show this set as it is not a known type
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, false);
        }
        renderer.setSeriesPaint(i, getKMSetColor(kmPlotSets, kmSeries.getKey(), kmSeries.getType()), true);
    }

    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    plot.setRenderer(renderer);

    /* change the auto tick unit selection to integer units only... */
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    /* OPTIONAL CUSTOMISATION COMPLETED. */
    rangeAxis.setAutoRange(true);
    rangeAxis.setRange(0.0, 1.0);

    /* set Title and Legend */
    chart.setTitle(title);
    createLegend(chart, kmPlotSets);

    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.SimpleBar.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }//from  w w  w.j  av a  2  s  .co  m

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    // set the background color for the chart...
    chart.setBackgroundPaint(color);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);

    if (firstAxisLB != null && firstAxisUB != null) {
        rangeAxis.setLowerBound(firstAxisLB);
        rangeAxis.setUpperBound(firstAxisUB);
    }

    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    } else
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // add
    CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}");
    renderer.setLegendItemLabelGenerator(generator);

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    if (showValueLabels) {
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        //         if(valueLabelsPosition.equalsIgnoreCase("inside")){
        //         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        //         renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
        //         } else {
        //         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        //         renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
        //         ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
        //         }

    }

    // PROVA LEGENDA      
    if (legend == true) {

        drawLegend(chart);

        /*BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0));
                
        LabelBlock titleBlock = new LabelBlock("Legend Items:",
              new Font("SansSerif", Font.BOLD, 12));
        title.setPadding(5, 5, 5, 5);
        wrapper.add(titleBlock, RectangleEdge.TOP);
                
        LegendTitle legend = new LegendTitle(chart.getPlot());
        BlockContainer items = legend.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend.setWrapper(wrapper);
                
        if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM);
        else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT);
        else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT);
        else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP);
        else legend.setPosition(RectangleEdge.BOTTOM);
                
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        chart.addSubtitle(legend);*/
    }

    int seriesN = dataset.getRowCount();

    // the order color vedctor overrides the color map!!

    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        logger.debug("color serie by SERIES_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);
            String labelName = "";
            int index = -1;
            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serieName;
                serieName = (String) seriesCaptions.get(serieName);
                index = dataset.getRowIndex(labelName);
            } else
                index = dataset.getRowIndex(serieName);

            Color color = (Color) colorMap.get(serieName);
            if (color != null) {
                //renderer.setSeriesPaint(i, color);
                renderer.setSeriesPaint(index, color);
                renderer.setSeriesItemLabelFont(i,
                        new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
                renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor());
            }
        }
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    domainAxis.setUpperMargin(0.10);
    logger.debug("OUT");
    return chart;

}