Example usage for org.jfree.chart.plot.dial StandardDialScale getMajorTickIncrement

List of usage examples for org.jfree.chart.plot.dial StandardDialScale getMajorTickIncrement

Introduction

In this page you can find the example usage for org.jfree.chart.plot.dial StandardDialScale getMajorTickIncrement.

Prototype

public double getMajorTickIncrement() 

Source Link

Document

Returns the increment (in data units) between major tick labels.

Usage

From source file:org.pentaho.chart.plugin.jfreechart.dial.JFreeDialChartGeneratorIT.java

public void testScale() throws Exception {
    JFreeChart chart = getJFreeChart("testchart.xml", new Object[][] { { 8D } }); //$NON-NLS-1$
    DialPlot plot = (DialPlot) chart.getPlot();
    StandardDialScale scale = (StandardDialScale) plot.getScale(0);
    assertEquals(-20D, scale.getLowerBound());
    assertEquals(20D, scale.getUpperBound());
    assertEquals(-135D, scale.getStartAngle());
    assertEquals(-180D, scale.getExtent());

    assertEquals(5D, scale.getMajorTickIncrement());
    assertEquals(2, scale.getMinorTickCount());

    assertEquals(new Color(255, 105, 180) /*hotpink*/, scale.getTickLabelPaint());
    assertEquals(12, scale.getTickLabelFont().getSize());
    assertEquals(Font.ITALIC | Font.BOLD, scale.getTickLabelFont().getStyle());
    // had trouble getting a font comparison to work without breaking it down into size, style, and name
    assertEquals("Monospaced", scale.getTickLabelFont().getName()); //$NON-NLS-1$

    assertEquals(5F, ((BasicStroke) scale.getMajorTickStroke()).getLineWidth());
    assertEquals(3F, ((BasicStroke) scale.getMinorTickStroke()).getLineWidth());

    assertEquals(0.10D, scale.getMajorTickLength());
    assertEquals(0.05D, scale.getMinorTickLength());

}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

/**
 *
 *//*  w  w  w . j a  v  a2 s  .  co  m*/
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false);

    GradientPaint gp2 = new GradientPaint(new Point(), Color.GRAY, new Point(), Color.BLACK);

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    //dialPlot.setView(0.0, 0.0, 1.0, 1.0);
    if (getDataset() != null) {
        dialPlot.setDataset((ValueDataset) getDataset());
    }
    StandardDialFrame dialFrame = new StandardDialFrame();
    //dialFrame.setRadius(0.60);
    //dialFrame.setBackgroundPaint(gp2);
    dialFrame.setForegroundPaint(gp2);
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialPlot.setBackground(db);
    StandardDialScale scale = null;
    int dialUnitScale = 1;
    Range range = convertRange(jrPlot.getDataRange());
    if (range != null) {
        double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));
        dialUnitScale = ChartThemesUtilities.getScale(bound);

        double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale);
        double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale);

        scale = new StandardDialScale(lowerBound, upperBound, 225, -270, (upperBound - lowerBound) / 6, 15);
        if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound
                && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) {
            scale.setTickLabelFormatter(new DecimalFormat("#,##0"));
        } else if (dialUnitScale == 1) {

            scale.setTickLabelFormatter(new DecimalFormat("#,##0.0"));
        } else if (dialUnitScale <= 0) {
            scale.setTickLabelFormatter(new DecimalFormat("#,##0.00"));
        }

    } else {
        scale = new StandardDialScale();
    }
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    JRFont tickLabelFont = jrPlot.getTickLabelFont();
    Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.BASEFONT_SIZE);
    Font themeTickLabelFont = getFont(
            (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT),
            tickLabelFont, defaultBaseFontSize);
    scale.setTickLabelFont(themeTickLabelFont);
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.3f));
    scale.setMajorTickPaint(Color.WHITE);
    scale.setMinorTickPaint(Color.WHITE);
    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);
    dialPlot.addScale(0, scale);

    List intervals = jrPlot.getIntervals();
    if (intervals != null && intervals.size() > 0) {
        int size = Math.min(3, intervals.size());
        int colorStep = 0;
        if (size > 3)
            colorStep = 255 / (size - 3);

        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = (JRMeterInterval) intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());
            double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(),
                    dialUnitScale);
            double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(),
                    dialUnitScale);

            Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i)
                    : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0);

            ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound,
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 12f);
            dialRange.setInnerRadius(0.41);
            dialRange.setOuterRadius(0.41);
            dialPlot.addLayer(dialRange);
        }
    }

    JRValueDisplay display = jrPlot.getValueDisplay();
    String displayVisibility = display != null && getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE)
            : "false";
    if (Boolean.parseBoolean(displayVisibility)) {
        ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale);
        dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        //         dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
        dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
        dvi.setPaint(Color.WHITE);

        String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
        if (pattern != null)
            dvi.setNumberFormat(new DecimalFormat(pattern));
        dvi.setRadius(0.15);
        dvi.setValueAnchor(RectangleAnchor.CENTER);
        dvi.setTextAnchor(TextAnchor.CENTER);
        //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale)));
        dialPlot.addLayer(dvi);
    }
    String label = getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL)
            : null;

    if (label != null) {
        JRFont displayFont = jrPlot.getValueDisplay().getFont();
        Font themeDisplayFont = getFont(
                (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT),
                displayFont, defaultBaseFontSize);
        if (dialUnitScale < 0)
            label = new MessageFormat(label)
                    .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) });
        else if (dialUnitScale < 3)
            label = new MessageFormat(label).format(new Object[] { "1" });
        else
            label = new MessageFormat(label)
                    .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) });

        String[] textLines = label.split("\\n");
        for (int i = 0; i < textLines.length; i++) {
            DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
            dialAnnotation.setFont(themeDisplayFont);
            dialAnnotation.setPaint(Color.WHITE);
            dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    //DialPointer needle = new DialPointer.Pointer();
    Paint paint = new Color(191, 48, 0);
    DialPointer needle = new ScaledDialPointer(dialUnitScale, paint, paint);

    needle.setVisible(true);
    needle.setRadius(0.91);
    dialPlot.addLayer(needle);

    DialCap cap = new DialCap();
    cap.setRadius(0.05);
    cap.setFillPaint(Color.DARK_GRAY);
    cap.setOutlinePaint(Color.GRAY);
    cap.setOutlineStroke(new BasicStroke(0.5f));
    dialPlot.setCap(cap);

    JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null,
            dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue());

    // Set all the generic options
    configureChart(jfreeChart, getPlot());

    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);

    return jfreeChart;

}

From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false);

    GradientPaint gp2 = new GradientPaint(new Point(), Color.GRAY, new Point(), Color.BLACK);

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    //dialPlot.setView(0.0, 0.0, 1.0, 1.0);
    if (getDataset() != null) {
        dialPlot.setDataset((ValueDataset) getDataset());
    }//from  w  w  w  .  j  a v  a  2s  .co m
    StandardDialFrame dialFrame = new StandardDialFrame();
    //dialFrame.setRadius(0.60);
    //dialFrame.setBackgroundPaint(gp2);
    dialFrame.setForegroundPaint(gp2);
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialPlot.setBackground(db);
    StandardDialScale scale = null;
    int dialUnitScale = 1;
    Range range = convertRange(jrPlot.getDataRange());
    if (range != null) {
        double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));
        dialUnitScale = ChartThemesUtilities.getScale(bound);

        double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale);
        double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale);
        int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7;
        scale = new StandardDialScale(lowerBound, upperBound, 225, -270,
                (upperBound - lowerBound) / (tickCount - 1), 15);
        if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound
                && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) {
            scale.setTickLabelFormatter(
                    new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale())));
        } else if (dialUnitScale == 1) {

            scale.setTickLabelFormatter(
                    new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale())));
        } else if (dialUnitScale <= 0) {
            scale.setTickLabelFormatter(
                    new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale())));
        } else {
            // localizing the default tick label formatter
            scale.setTickLabelFormatter(
                    new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale())));
        }

    } else {
        scale = new StandardDialScale();

        // localizing the default tick label formatter
        scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale())));
    }
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    JRFont tickLabelFont = jrPlot.getTickLabelFont();
    Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.BASEFONT_SIZE);
    Font themeTickLabelFont = getFont(
            (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT),
            tickLabelFont, defaultBaseFontSize);
    scale.setTickLabelFont(themeTickLabelFont);
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.3f));
    scale.setMajorTickPaint(Color.WHITE);
    scale.setMinorTickPaint(Color.WHITE);
    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);

    dialPlot.addScale(0, scale);

    List<JRMeterInterval> intervals = jrPlot.getIntervals();
    if (intervals != null && intervals.size() > 0) {
        int size = Math.min(3, intervals.size());
        int colorStep = 0;
        if (size > 3)
            colorStep = 255 / (size - 3);

        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());
            double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(),
                    dialUnitScale);
            double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(),
                    dialUnitScale);

            Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i)
                    : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0);

            ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound,
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 12f);
            dialRange.setInnerRadius(0.41);
            dialRange.setOuterRadius(0.41);
            dialPlot.addLayer(dialRange);
        }
    }

    JRValueDisplay display = jrPlot.getValueDisplay();
    String displayVisibility = display != null && getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE)
            : "false";
    if (Boolean.parseBoolean(displayVisibility)) {
        ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale);
        dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        //         dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
        dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
        dvi.setPaint(Color.WHITE);

        String pattern = display.getMask() != null ? display.getMask() : "#,##0.####";
        if (pattern != null)
            dvi.setNumberFormat(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale())));
        dvi.setRadius(0.15);
        dvi.setValueAnchor(RectangleAnchor.CENTER);
        dvi.setTextAnchor(TextAnchor.CENTER);
        //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale)));
        dialPlot.addLayer(dvi);
    }
    String label = getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL)
            : null;

    if (label != null) {
        JRFont displayFont = jrPlot.getValueDisplay().getFont();
        Font themeDisplayFont = getFont(
                (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT),
                displayFont, defaultBaseFontSize);
        if (dialUnitScale < 0)
            label = new MessageFormat(label)
                    .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) });
        else if (dialUnitScale < 3)
            label = new MessageFormat(label).format(new Object[] { "1" });
        else
            label = new MessageFormat(label)
                    .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) });

        String[] textLines = label.split("\\n");
        for (int i = 0; i < textLines.length; i++) {
            DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
            dialAnnotation.setFont(themeDisplayFont);
            dialAnnotation.setPaint(Color.WHITE);
            dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    //DialPointer needle = new DialPointer.Pointer();
    Paint paint = new Color(191, 48, 0);
    DialPointer needle = new ScaledDialPointer(dialUnitScale, paint, paint);

    needle.setVisible(true);
    needle.setRadius(0.91);
    dialPlot.addLayer(needle);

    DialCap cap = new DialCap();
    cap.setRadius(0.05);
    cap.setFillPaint(Color.DARK_GRAY);
    cap.setOutlinePaint(Color.GRAY);
    cap.setOutlineStroke(new BasicStroke(0.5f));
    dialPlot.setCap(cap);

    JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null,
            dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend());

    // Set all the generic options
    configureChart(jfreeChart, getPlot());

    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);

    return jfreeChart;

}