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

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

Introduction

In this page you can find the example usage for org.jfree.chart.axis Axis 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.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 av a  2  s .  c o  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.openfaces.component.chart.impl.helpers.AxisUtil.java

public static void setupAxisPresentation(String label, Axis axis, FakeAxisStyle axisStyle) {
    StyleObjectModel model = axisStyle.getStyleObjectModel();
    StyleBorderModel border = model.getBorder();
    if (border != null) {
        if (border.getColor() != null) {
            axis.setAxisLinePaint(border.getColor());
        }//from ww  w. java 2s.  co m

        if (!border.isNone()) {
            axis.setAxisLineVisible(true);
            axis.setAxisLineStroke(PropertiesConverter.toStroke(border));
            axis.setTickMarkPaint(border.getColor());
            axis.setTickMarksVisible(true);
            if (!axis.isTickMarksVisible())
                axis.setTickMarksVisible(false);
        }

        if (border.getStyle().equalsIgnoreCase("none")) {
            axis.setAxisLineVisible(false);
            axis.setTickMarksVisible(false);
            if (axis.isTickMarksVisible())
                axis.setTickMarksVisible(true);
        }

    }

    axis.setTickLabelsVisible(axisStyle.isTickLabelsVisible());

    if (axisStyle.isLabelVisible() && label != null) {
        axis.setLabel(label);
        axis.setLabelPaint(model.getColor());
        axis.setLabelFont(CSSUtil.getFont(model));
    }

    if (axisStyle.isTickLabelsVisible()) {
        axis.setTickLabelsVisible(true);
        axis.setTickLabelPaint(model.getColor());
        axis.setTickLabelFont(CSSUtil.getFont(model));
    } else {
        axis.setTickLabelsVisible(false);
    }

    Double tickInterval = axisStyle.getTickInterval();
    if (tickInterval != null && tickInterval != 0 && axis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) axis;
        if (tickInterval > 0) {
            NumberTickUnit tickUnit = new NumberTickUnit(tickInterval);
            numberAxis.setTickUnit(tickUnit);
        } else if (tickInterval == -1) {
            TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits();
            numberAxis.setStandardTickUnits(tickUnits);
        } else {
            throw new FacesException("tickInterval must be a positive number for a fixed tick interval, "
                    + "or -1 for automatic integer tick selection: " + tickInterval);
        }

        numberAxis.setMinorTickMarksVisible(true);
        numberAxis.setMinorTickCount(2);
        numberAxis.setMinorTickMarkOutsideLength(3);
        numberAxis.setMinorTickMarkInsideLength(3);
        numberAxis.setTickMarkInsideLength(5);
        numberAxis.setTickMarkOutsideLength(5);
    }

    axis.setTickMarkInsideLength(axisStyle.getTickInsideLength());
    axis.setTickMarkOutsideLength(axisStyle.getTickOutsideLength());
    if (axisStyle.getMinorTicksVisible()) {
        axis.setMinorTickMarksVisible(true);
        if (axis instanceof ValueAxis)
            ((ValueAxis) axis).setMinorTickCount(axisStyle.getMinorTickCount() + 1);
        axis.setMinorTickMarkInsideLength(axisStyle.getMinorTickInsideLength());
        axis.setMinorTickMarkOutsideLength(axisStyle.getMinorTickOutsideLength());
    } else {
        axis.setMinorTickMarksVisible(false);
    }
}

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  ww w  .  ja  va2s.  c o m
public static JFreeChart getChart(int reportId, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportId);
    JFreeChart chart = null;
    try {
        /*
         * Create data set based on rsw object.
         */
        ReportColumnBean reportColumnBean = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        CustomCategoryDataset dataset = new CustomCategoryDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBean.getDbColumnName();
        reportColumnBean.getColumnName();

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

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

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

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

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

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

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

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

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

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

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeAxis(Axis axis, ChartParams params, String prefix) {

    if (params.get(prefix + ChartParams.AXIS_VISIBLE_SUFIX) != null
            && params.getBoolean(prefix + ChartParams.AXIS_VISIBLE_SUFIX).booleanValue() == false) {
        axis.setVisible(false);//from   w  ww  .j a  v a 2  s .c om

    } else {
        if (params.get(prefix + ChartParams.AXIS_LINE_VISIBLE_SUFFIX) != null) {
            if (params.getBoolean(prefix + ChartParams.AXIS_LINE_VISIBLE_SUFFIX).booleanValue()) {
                axis.setAxisLineVisible(true);

                if (params.get(prefix + ChartParams.AXIS_LINE_COLOR_SUFFIX) != null) {
                    axis.setAxisLinePaint(params.getColor(prefix + ChartParams.AXIS_LINE_COLOR_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_LINE_STROKE_SUFFIX) != null) {
                    axis.setAxisLineStroke(params.getStroke(prefix + ChartParams.AXIS_LINE_STROKE_SUFFIX));
                }
            } else {
                axis.setAxisLineVisible(false);
            }
        }

        if (params.get(prefix + ChartParams.AXIS_LABEL_SUFFIX) != null) {
            axis.setLabel(params.getString(prefix + ChartParams.AXIS_LABEL_SUFFIX));

            if (params.get(prefix + ChartParams.AXIS_LABEL_FONT_SUFFIX) != null) {
                axis.setLabelFont(params.getFont(prefix + ChartParams.AXIS_LABEL_FONT_SUFFIX));
            }

            if (params.get(prefix + ChartParams.AXIS_LABEL_COLOR_SUFFIX) != null) {
                axis.setLabelPaint(params.getColor(prefix + ChartParams.AXIS_LABEL_COLOR_SUFFIX));
            }

            if (params.get(prefix + ChartParams.AXIS_LABEL_INSERTS_SUFFIX) != null) {
                axis.setLabelInsets(params.getRectangleInsets(prefix + ChartParams.AXIS_LABEL_INSERTS_SUFFIX));
            }
        }

        if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_VISIBLE_SUFFIX) != null) {
            if (params.getBoolean(prefix + ChartParams.AXIS_TICK_LABEL_VISIBLE_SUFFIX).booleanValue()) {
                axis.setTickLabelsVisible(true);

                if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_FONT_SUFFIX) != null) {
                    axis.setTickLabelFont(params.getFont(prefix + ChartParams.AXIS_TICK_LABEL_FONT_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_COLOR_SUFFIX) != null) {
                    axis.setTickLabelPaint(params.getColor(prefix + ChartParams.AXIS_TICK_LABEL_COLOR_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_LABEL_INSERTS_SUFFIX) != null) {
                    axis.setTickLabelInsets(
                            params.getRectangleInsets(prefix + ChartParams.AXIS_TICK_LABEL_INSERTS_SUFFIX));
                }

            } else {
                axis.setTickLabelsVisible(false);
            }
        }

        if (params.get(prefix + ChartParams.AXIS_TICK_MARK_VISIBLE_SUFFIX) != null) {
            if (params.getBoolean(prefix + ChartParams.AXIS_TICK_MARK_VISIBLE_SUFFIX).booleanValue()) {
                axis.setTickMarksVisible(true);

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_INSIDE_LENGTH_SUFFIX) != null) {
                    axis.setTickMarkInsideLength(params
                            .getFloat(prefix + ChartParams.AXIS_TICK_MARK_INSIDE_LENGTH_SUFFIX).floatValue());
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_OUTSIDE_LENGTH_SUFFIX) != null) {
                    axis.setTickMarkOutsideLength(params
                            .getFloat(prefix + ChartParams.AXIS_TICK_MARK_OUTSIDE_LENGTH_SUFFIX).floatValue());
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_COLOR_SUFFIX) != null) {
                    axis.setTickMarkPaint(params.getColor(prefix + ChartParams.AXIS_TICK_MARK_COLOR_SUFFIX));
                }

                if (params.get(prefix + ChartParams.AXIS_TICK_MARK_COLOR_SUFFIX) != null) {
                    axis.setTickMarkStroke(params.getStroke(prefix + ChartParams.AXIS_TICK_MARK_STROKE_SUFFIX));
                }

            } else {
                axis.setTickMarksVisible(false);
            }
        }
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

protected void setAxisStyles(Axis axis, UIAxis comp) {
    axis.setVisible(comp.isVisible());/*from   w w  w. j  ava2s  . c o  m*/
    axis.setAxisLineVisible(comp.isDrawLine());
    axis.setTickLabelsVisible(comp.isDrawTickLabels());
    axis.setTickMarksVisible(comp.isDrawTickMarks());

    String label = comp.getLabel();
    Font labelFont = comp.getLabelFont();
    Paint labelColor = comp.getLabelColor();
    Paint lineColor = comp.getLineColor();
    Font tickLabelFont = comp.getTickLabelFont();
    Paint tickLabelColor = comp.getTickLabelColor();
    Paint tickMarkColor = comp.getTickMarkColor();

    if (label != null)
        axis.setLabel(label);
    if (labelFont != null)
        axis.setLabelFont(labelFont);
    if (labelColor != null)
        axis.setLabelPaint(labelColor);
    if (lineColor != null)
        axis.setAxisLinePaint(lineColor);
    if (tickLabelFont != null)
        axis.setTickLabelFont(tickLabelFont);
    if (tickLabelColor != null)
        axis.setTickLabelPaint(tickLabelColor);
    if (tickMarkColor != null)
        axis.setTickMarkPaint(tickMarkColor);
    axis.setTickMarkInsideLength(comp.getTickMarkInsideLength());
    axis.setTickMarkOutsideLength(comp.getTickMarkOutsideLength());

    if (axis instanceof CategoryAxis) {
        setCategoryAxisStyles((CategoryAxis) axis, comp);
    } else if (axis instanceof DateAxis) {
        setDateAxisStyles((DateAxis) axis, comp);
    } else if (axis instanceof NumberAxis) {
        setNumberAxisStyles((NumberAxis) axis, comp);
    }
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setAxisLine(Axis axis, Paint lineColor, AxisSettings axisSettings) {
    Boolean axisLineVisible = axisSettings.getLineVisible();
    if (axisLineVisible == null || axisLineVisible.booleanValue()) {
        Paint linePaint = lineColor;
        if (linePaint == null && axisSettings.getLinePaint() != null) {
            linePaint = axisSettings.getLinePaint().getPaint();
        }/*from  www  .j a v a2 s.c  o  m*/
        if (linePaint != null) {
            axis.setAxisLinePaint(linePaint);
        }
        Stroke axisLineStroke = axisSettings.getLineStroke();
        if (axisLineStroke != null)
            axis.setAxisLineStroke(axisLineStroke);
    } else {
        axis.setAxisLineVisible(false);
    }
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setAxisLine(Axis axis, Paint lineColor, AxisSettings axisSettings) {
    Boolean axisLineVisible = axisSettings.getLineVisible();
    if (axisLineVisible == null || axisLineVisible) {
        Paint linePaint = lineColor;
        if (linePaint == null && axisSettings.getLinePaint() != null) {
            linePaint = axisSettings.getLinePaint().getPaint();
        }/*from ww  w .ja va  2 s .  c  om*/
        if (linePaint != null) {
            axis.setAxisLinePaint(linePaint);
        }
        Stroke axisLineStroke = axisSettings.getLineStroke();
        if (axisLineStroke != null)
            axis.setAxisLineStroke(axisLineStroke);
    } else {
        axis.setAxisLineVisible(false);
    }
}