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

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

Introduction

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

Prototype

public void setTickLabelFont(Font font) 

Source Link

Document

Sets the font for the tick labels and sends an AxisChangeEvent to all registered listeners.

Usage

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  w w.jav a2  s .  c  om*/
    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.jfree.chart.demo.XYBlockChartDemo1.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.0D);//from ww w .  ja  v a2 s .  c o  m
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setAxisLinePaint(Color.white);
    numberaxis.setTickMarkPaint(Color.white);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setAxisLinePaint(Color.white);
    numberaxis1.setTickMarkPaint(Color.white);
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    GrayPaintScale graypaintscale = new GrayPaintScale(-2D, 1.0D);
    xyblockrenderer.setPaintScale(graypaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setOutlinePaint(Color.blue);
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Scale");
    numberaxis2.setAxisLinePaint(Color.white);
    numberaxis2.setTickMarkPaint(Color.white);
    numberaxis2.setTickLabelFont(new Font("Dialog", 0, 7));
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(new GrayPaintScale(), numberaxis2);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    paintscalelegend.setFrame(new BlockBorder(Color.red));
    paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
    paintscalelegend.setStripWidth(10D);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setBackgroundPaint(new Color(120, 120, 180));
    jfreechart.addSubtitle(paintscalelegend);
    jfreechart.setBackgroundPaint(new Color(180, 180, 250));
    return jfreechart;
}

From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java

private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints,
        XYDataset xyData) {/*from w w  w .j a  va2 s . c  o  m*/
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0], maxs[0]);

    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);

    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}

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

public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;//from  w w w  .  ja v a  2  s . c  o m
    //   DefaultCategoryDataset dataset=null;
    CustomCategoryDataset datasetCustom = null;

    try {
        ReportColumnBean reportColumnBeanX = null;
        ReportColumnBean reportColumnBeanY = null;
        ReportColumnBean reportColumnBeanZ = null;
        GraphBean graphBean = null;

        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBeanX.getDbColumnName();
        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBeanY.getDbColumnName();
        String zColumnDBname = null;

        datasetCustom = new CustomCategoryDataset();
        rsw.beforeFirst();
        String data = "";
        int count = -1;
        Boolean showLegend = false;
        if (graphBean.getZColumnId() == -1) {

            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), "", data);
            }

        } else {
            String zData;
            showLegend = true;
            reportColumnBeanZ = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                    graphBean.getZColumnId());
            zColumnDBname = reportColumnBeanZ.getDbColumnName();
            while (rsw.next()) {
                data = rsw.getString(xColumnDBname);
                zData = rsw.getString(zColumnDBname);
                datasetCustom.addValue(rsw.getLong(yColumnDBname), zData, data);
                count++;
            }

        }
        chart = ChartFactory.createLineChart("", // chart title
                "", // domain axis label
                "", // range axis label
                datasetCustom, // data
                PlotOrientation.VERTICAL, // orientation
                showLegend, // include legend
                true, // tooltips
                false // urls
        );
        LegendTitle legendTitle = chart.getLegend();
        if (legendTitle != null)
            legendTitle.setItemFont(new Font("Vandara", Font.BOLD, 11));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelInsets(new RectangleInsets(0, 0, 0, 5));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);
        CustomDomainAxis catAxis = new CustomDomainAxis();
        CustomDomainAxis.counter = 0;
        CustomDomainAxis.colCount = datasetCustom.getColumnCount();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setTickLabelInsets(new RectangleInsets(10, 15, 30, 10));
        catAxis.setAxisLineVisible(false);
        catAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(20 * Math.PI / 180));
        plot.setDomainAxis(catAxis);
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        if (count > 0) {
            Color[] colors = null;
            colors = new Color[5];
            colors[0] = new Color(24, 112, 176);
            colors[1] = new Color(168, 192, 232);
            colors[2] = new Color(248, 120, 8);
            colors[3] = new Color(248, 184, 120);
            colors[4] = new Color(152, 216, 136);
            for (int i = 0; i < count && i < colors.length; i++)
                renderer.setSeriesPaint(i, colors[i]);
        }
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("LineChart: " + e.getMessage(), e);
    }
    return chart;
}

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

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

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

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

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

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

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

    return chart;
}

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

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

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

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

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

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

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

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

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

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

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

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

From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java

private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18));
    jfreechart.setBackgroundPaint(new Color(221, 223, 238));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    //categoryplot.setBackgroundPaint(new Color(221, 223, 238));

    renderer.setSeriesPaint(0, new Color(130, 165, 70));
    renderer.setSeriesPaint(1, new Color(220, 165, 70));
    renderer.setSeriesPaint(4, new Color(255, 165, 70));
    renderer.setDrawBarOutline(false);/*from w  ww .j  a v a 2s.  c o  m*/
    renderer.setShadowVisible(false);
    // renderer.setMaximumBarWidth(1);
    renderer.setGradientPaintTransformer(null);
    renderer.setDefaultBarPainter(new StandardBarPainter());

    categoryplot.setRenderer(renderer);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.25D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null));
    numberaxis.setRange(0, 100);
    //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
    numberaxis.setTickLabelFont(font);
    CategoryAxis axisd = categoryplot.getDomainAxis();
    ValueAxis axisr = categoryplot.getRangeAxis();
    axisd.setTickLabelFont(font);
    axisr.setTickLabelFont(font);

    final ChartPanel chartPanel = new ChartPanel(jfreechart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));

    FileOutputStream output;
    try {
        output = new FileOutputStream("successGlobalRates" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jfreechart;
}

From source file:unalcol.termites.boxplots.SucessfulRatesHybrid.java

private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18));
    jfreechart.setBackgroundPaint(new Color(221, 223, 238));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    //categoryplot.setBackgroundPaint(new Color(221, 223, 238));

    renderer.setSeriesPaint(0, new Color(130, 165, 70));
    renderer.setSeriesPaint(1, new Color(220, 165, 70));
    renderer.setSeriesPaint(4, new Color(255, 165, 70));
    renderer.setDrawBarOutline(false);//from  w  ww .j  a  v  a 2 s . com
    renderer.setShadowVisible(false);
    // renderer.setMaximumBarWidth(1);
    renderer.setGradientPaintTransformer(null);
    renderer.setDefaultBarPainter(new StandardBarPainter());

    categoryplot.setRenderer(renderer);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.25D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null));
    numberaxis.setRange(0, 100);
    //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
    numberaxis.setTickLabelFont(font);
    CategoryAxis axisd = categoryplot.getDomainAxis();
    ValueAxis axisr = categoryplot.getRangeAxis();
    axisd.setTickLabelFont(font);
    axisr.setTickLabelFont(font);

    axisd.setMaximumCategoryLabelLines(5);

    final ChartPanel chartPanel = new ChartPanel(jfreechart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1300, 370));

    FileOutputStream output;
    try {
        output = new FileOutputStream("sucessrates1" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 1300, 370, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jfreechart;
}

From source file:unalcol.termites.boxplots.SucessfulRates.java

private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18));
    jfreechart.setBackgroundPaint(new Color(221, 223, 238));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    //categoryplot.setBackgroundPaint(new Color(221, 223, 238));

    renderer.setSeriesPaint(0, new Color(130, 165, 70));
    renderer.setSeriesPaint(1, new Color(220, 165, 70));
    renderer.setSeriesPaint(4, new Color(255, 165, 70));
    renderer.setDrawBarOutline(false);//from   ww w  .j a va2  s  . c  o m
    renderer.setShadowVisible(false);
    // renderer.setMaximumBarWidth(1);
    renderer.setGradientPaintTransformer(null);
    renderer.setDefaultBarPainter(new StandardBarPainter());

    categoryplot.setRenderer(renderer);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.25D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null));
    numberaxis.setRange(0, 100);
    //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
    numberaxis.setTickLabelFont(font);
    CategoryAxis axisd = categoryplot.getDomainAxis();
    ValueAxis axisr = categoryplot.getRangeAxis();
    axisd.setTickLabelFont(font);
    axisr.setTickLabelFont(font);

    final ChartPanel chartPanel = new ChartPanel(jfreechart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));

    FileOutputStream output;
    try {
        output = new FileOutputStream("sucessrates1" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jfreechart;
}