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

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

Introduction

In this page you can find the example usage for org.jfree.chart.axis Axis setTickMarksVisible.

Prototype

public void setTickMarksVisible(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the tick marks are showing 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.
 *///from   ww  w . java 2 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: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 ww .j a  v a 2s.  co 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: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   w  w w .jav a 2s. c o  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:net.sourceforge.processdash.ev.ui.chart.EVXYChartPanel.java

protected void adjustAxis(Axis a, boolean chromeless, String label) {
    boolean showAxisTickLabels = !chromeless && chartContainsData;

    a.setTickLabelsVisible(showAxisTickLabels);
    a.setTickMarksVisible(showAxisTickLabels);
    a.setLabel(chromeless ? null : label);
}

From source file:com.rcp.wbw.demo.editor.SWTAxisEditor.java

/**
 * Sets the properties of the specified axis to match
 * the properties defined on this panel.
 * //from w  ww. ja  va  2 s  .co  m
 * @param axis
 *            the axis.
 */
public void setAxisProperties(Axis axis) {
    axis.setLabel(getLabel());
    axis.setLabelFont(getLabelFont());
    axis.setLabelPaint(getLabelPaint());
    axis.setTickMarksVisible(this.showTickMarksCheckBox.getSelection());
    axis.setTickLabelsVisible(this.showTickLabelsCheckBox.getSelection());
    axis.setTickLabelFont(getTickLabelFont());
    axis.setTickLabelPaint(getTickLabelPaint());
}

From source file:ch.zhaw.simulation.diagram.charteditor.DefaultAxisEditor.java

/**
 * Sets the properties of the specified axis to match the properties defined
 * on this panel.//from w  ww . ja  va2s. co m
 * 
 * @param axis
 *            the axis.
 */
public void setAxisProperties(Axis axis) {
    axis.setLabel(getLabel());
    axis.setLabelFont(getLabelFont());
    axis.setLabelPaint(getLabelPaint());
    axis.setTickMarksVisible(isTickMarksVisible());
    axis.setTickLabelsVisible(isTickLabelsVisible());
    axis.setTickLabelFont(getTickLabelFont());
    axis.setTickLabelPaint(getTickLabelPaint());
    axis.setTickLabelInsets(getTickLabelInsets());
    axis.setLabelInsets(getLabelInsets());
}

From source file:daylightchart.options.chart.AxisOptions.java

/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.//from   ww  w .java  2s .  co m
 *
 * @param axis
 *        the axis.
 */
void setAxisProperties(final Axis axis) {
    axis.setLabel(label);
    if (labelFont != null) {
        axis.setLabelFont(labelFont);
    }
    if (labelPaint != null) {
        axis.setLabelPaint(labelPaint);
    }
    if (labelInsets != null) {
        axis.setLabelInsets(labelInsets);
    }
    //
    axis.setTickMarksVisible(tickMarksVisible);
    axis.setTickLabelsVisible(tickLabelsVisible);
    if (tickLabelFont != null) {
        axis.setTickLabelFont(tickLabelFont);
    }
    if (tickLabelPaint != null) {
        axis.setTickLabelPaint(tickLabelPaint);
    }
    if (tickLabelInsets != null) {
        axis.setTickLabelInsets(tickLabelInsets);
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Processes a string that indicates the axes that should be visible on
 * the plot./*from  w w w. ja va  2  s  . c o  m*/
 *
 * @param plot  the plot.
 * @param axisStr  the axis specification.
 * @param axes  a list that will be populated with any axes added to the
 *              plot.
 */
private static void processAxisStr(XYPlot plot, String axisStr, List axes) {
    int xAxisCount = 0;
    int yAxisCount = 0;
    for (int i = 0; i < axisStr.length(); i++) {
        char c = axisStr.charAt(i);
        if (c == 'x') {
            if (xAxisCount == 0) {
                Axis xAxis = plot.getDomainAxis();
                xAxis.setTickMarksVisible(true);
                xAxis.setTickLabelsVisible(true);
                axes.add(xAxis);
                xAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setDomainAxis(xAxisCount, axis);
                plot.setDomainAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                xAxisCount++;
            }
        } else if (c == 'y') {
            if (yAxisCount == 0) {
                Axis yAxis = plot.getRangeAxis();
                yAxis.setTickMarksVisible(true);
                yAxis.setTickLabelsVisible(true);
                axes.add(yAxis);
                yAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setRangeAxis(yAxisCount, axis);
                plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                yAxisCount++;
            }
        } else if (c == 'r') {
            GValueAxis axis = new GValueAxis();
            plot.setRangeAxis(yAxisCount, axis);
            plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_RIGHT);
            axes.add(axis);
            yAxisCount++;
        } else if (c == 't') {
            GValueAxis axis = new GValueAxis();
            plot.setDomainAxis(xAxisCount, axis);
            plot.setDomainAxisLocation(xAxisCount, AxisLocation.TOP_OR_LEFT);
            axes.add(axis);
            xAxisCount++;
        } else if (c == ',') {
            // nothing to do
        } else {
            throw new RuntimeException("Bad character " + c);
        }
    }

}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Processes a string that indicates the axes that should be visible on
 * the plot./*from w  ww  .ja v  a2  s  .c  o m*/
 *
 * @param plot  the plot.
 * @param axisStr  the axis specification.
 * @param axes  a list that will be populated with any axes added to the
 *              plot.
 */
private static void processAxisStrV(CategoryPlot plot, String axisStr, List axes) {
    int xAxisCount = 0;
    int yAxisCount = 0;
    for (int i = 0; i < axisStr.length(); i++) {
        char c = axisStr.charAt(i);
        if (c == 'x') {
            if (xAxisCount == 0) {
                CategoryAxis xAxis = plot.getDomainAxis();
                xAxis.setTickLabelsVisible(true);
                axes.add(xAxis);
                xAxisCount++;
            } else {
                GCategoryAxis axis = new GCategoryAxis();
                axis.setAxisLineVisible(false);
                plot.setDomainAxis(xAxisCount, axis);
                plot.setDomainAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                xAxisCount++;
            }
        } else if (c == 'y') {
            if (yAxisCount == 0) {
                Axis yAxis = plot.getRangeAxis();
                yAxis.setTickLabelsVisible(true);
                yAxis.setTickMarksVisible(true);
                axes.add(yAxis);
                yAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setRangeAxis(yAxisCount, axis);
                plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                yAxisCount++;
            }
        } else if (c == 'r') {
            GValueAxis axis = new GValueAxis();
            plot.setRangeAxis(yAxisCount, axis);
            plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_RIGHT);
            axes.add(axis);
            yAxisCount++;
        } else if (c == 't') {
            GCategoryAxis axis = new GCategoryAxis();
            axis.setAxisLineVisible(false);
            plot.setDomainAxis(xAxisCount, axis);
            plot.setDomainAxisLocation(xAxisCount, AxisLocation.TOP_OR_LEFT);
            axes.add(axis);
            xAxisCount++;
        } else if (c == ',') {
            // nothing to do
        } else {
            throw new RuntimeException("Bad character " + c);
        }
    }

}

From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java

private static void applyAxisProperties(Axis axis, String prefix, Map<String, Object> properties) {
    axis.setLabel((String) properties.get(prefix + AXISLABEL));
    Font font = (Font) properties.get(prefix + AXISLABELFONT);
    if (font != null)
        axis.setLabelFont(font);//from   w  w w  . j  a va 2s.c o  m
    Paint paint = (Paint) properties.get(prefix + AXISLABELPAINT);
    if (paint != null)
        axis.setLabelPaint(paint);
    Boolean visible = (Boolean) properties.get(prefix + TICKMARKSVISIBLE);
    if (visible != null)
        axis.setTickMarksVisible(visible);
    visible = (Boolean) properties.get(prefix + TICKLABELSVISIBLE);
    if (visible != null)
        axis.setTickLabelsVisible(visible);
    font = (Font) properties.get(prefix + TICKLABELFONT);
    if (font != null)
        axis.setTickLabelFont(font);
    paint = (Paint) properties.get(prefix + TICKLABELPAINT);
    if (paint != null)
        axis.setTickLabelPaint(paint);
}