Example usage for org.jfree.eastwood GCategoryPlot setXAxisStepSize

List of usage examples for org.jfree.eastwood GCategoryPlot setXAxisStepSize

Introduction

In this page you can find the example usage for org.jfree.eastwood GCategoryPlot setXAxisStepSize.

Prototype

public void setXAxisStepSize(double axisStepSize) 

Source Link

Document

Sets the step size to use when drawing the grid lines for the x axis.

Usage

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

/**
 * Process a string which specifies grid line steps and line segment sizes.
 *
 * @param spec  the grid lines specification.
 * @param chart  the chart./*  w  ww  .jav a2  s.com*/
 */
private static void processGridLinesSpec(String spec, JFreeChart chart) {
    String[] parts = breakString(spec, ',');

    double xAxisStepSize = 0.0;
    double yAxisStepSize = 0.0;
    float lineSegLength = 3f;
    float blankSegLength = 6f;

    if (parts.length > 0) {
        try {
            xAxisStepSize = Double.parseDouble(parts[0]);
        } catch (NumberFormatException e) {

        }
    }
    if (parts.length > 1) {
        try {
            yAxisStepSize = Double.parseDouble(parts[1]);
        } catch (NumberFormatException e) {

        }
    }
    if (parts.length > 2) {
        try {
            lineSegLength = Float.parseFloat(parts[2]) * 0.85f;
        } catch (NumberFormatException e) {

        }
    }
    if (parts.length > 3) {
        try {
            blankSegLength = Float.parseFloat(parts[3]) * 0.85f;
        } catch (NumberFormatException e) {

        }
    }

    if (lineSegLength == 0 && blankSegLength == 0) {
        lineSegLength = 1f;
    }

    if (lineSegLength > 0) {
        Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10f,
                new float[] { lineSegLength, blankSegLength }, 0);

        Plot p = chart.getPlot();
        if (p instanceof CategoryPlot) {
            GCategoryPlot plot = (GCategoryPlot) p;
            plot.setDomainGridlinesVisible(true);
            plot.setRangeGridlinesVisible(true);
            plot.setDomainGridlineStroke(stroke);
            plot.setRangeGridlineStroke(stroke);
            plot.setXAxisStepSize(xAxisStepSize / 100.0);
            plot.setYAxisStepSize(yAxisStepSize / 100.0);
        } else if (p instanceof XYPlot) {
            GXYPlot plot = (GXYPlot) p;
            plot.setDomainGridlinesVisible(true);
            plot.setRangeGridlinesVisible(true);
            plot.setDomainGridlineStroke(stroke);
            plot.setRangeGridlineStroke(stroke);
            plot.setXAxisStepSize(xAxisStepSize / 100.0);
            plot.setYAxisStepSize(yAxisStepSize / 100.0);
        }
    }
}