Example usage for org.jfree.chart.plot.dial DialCap setOutlinePaint

List of usage examples for org.jfree.chart.plot.dial DialCap setOutlinePaint

Introduction

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

Prototype

public void setOutlinePaint(Paint paint) 

Source Link

Document

Sets the paint used to draw the outline of the cap and sends a DialLayerChangeEvent to all registered listeners.

Usage

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

/**
 *
 *//*  ww w .  ja  v a2 s .  c o  m*/
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    if (getDataset() != null) {
        dialPlot.setDataset((ValueDataset) getDataset());
    }
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setForegroundPaint(Color.BLACK);
    dialFrame.setBackgroundPaint(Color.BLACK);
    dialFrame.setStroke(new BasicStroke(1f));
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT);
    dialPlot.setBackground(db);
    ScaledDialScale 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 ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / 6, 1);
        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 ScaledDialScale();
    }
    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.7f));
    scale.setMajorTickPaint(Color.BLACK);
    scale.setMinorTickPaint(Color.BLACK);
    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(), 15f);
            dialRange.setInnerRadius(0.5);
            dialRange.setOuterRadius(0.5);
            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.valueOf(displayVisibility).booleanValue()) {
        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) {
        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)) });

        JRFont displayFont = jrPlot.getValueDisplay().getFont();
        Font themeDisplayFont = getFont(
                (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT),
                displayFont, defaultBaseFontSize);

        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.BLACK);
            dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047);

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

    DialCap cap = new DialCap();
    cap.setRadius(0.05);
    cap.setFillPaint(Color.BLACK);
    cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    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:org.pentaho.chart.plugin.jfreechart.chart.dial.JFreeDialChartGenerator.java

protected void setDialCap(ChartDocument chartDocument, DialPlot dialPlot) {
    // ~ params begin
    double capRadius = 0.05; // expressed as percentage of dial's framing rectangle 
    Color capFillPaint = Color.white;
    Color capOutlinePaint = Color.black;
    Stroke capOutlineStroke = new BasicStroke(2.0f);
    // ~ params end

    final StrokeFactory strokeFacObj = StrokeFactory.getInstance();

    ChartElement dialCapElement = getUniqueElement(chartDocument, DIALCAP);

    final BasicStroke borderStyleStroke = strokeFacObj.getBorderStroke(dialCapElement);
    if (borderStyleStroke != null) {
        capOutlineStroke = borderStyleStroke;
    }//from  ww  w  .  j a v  a2  s  .  co  m

    final Color borderColor = ColorFactory.getInstance().getColor(dialCapElement,
            BorderStyleKeys.BORDER_TOP_COLOR);
    if (borderColor != null) {
        capOutlinePaint = borderColor;
    }

    final Color capColor = ColorFactory.getInstance().getColor(dialCapElement);
    if (capColor != null) {
        capFillPaint = capColor;
    }

    capRadius = parseDouble(dialCapElement.getLayoutStyle().getValue(BoxStyleKeys.WIDTH)) / 100;

    DialCap dialCap = new DialCap();
    dialCap.setRadius(capRadius);
    dialCap.setFillPaint(capFillPaint);
    dialCap.setOutlinePaint(capOutlinePaint);
    dialCap.setOutlineStroke(capOutlineStroke);
    dialPlot.setCap(dialCap);
}

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

@Override
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    if (getDataset() != null) {
        dialPlot.setDataset((ValueDataset) getDataset());
    }//  www.  j a  va  2 s.  co  m
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setForegroundPaint(Color.BLACK);
    dialFrame.setBackgroundPaint(Color.BLACK);
    dialFrame.setStroke(new BasicStroke(1f));
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT);
    dialPlot.setBackground(db);
    ScaledDialScale 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 ScaledDialScale(lowerBound, upperBound, 210, -240,
                (upperBound - lowerBound) / (tickCount - 1), 1);
        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 ScaledDialScale();

        // 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.7f));
    scale.setMajorTickPaint(Color.BLACK);
    scale.setMinorTickPaint(Color.BLACK);
    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(), 15f);
            dialRange.setInnerRadius(0.5);
            dialRange.setOuterRadius(0.5);
            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.valueOf(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) {
        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)) });

        JRFont displayFont = jrPlot.getValueDisplay().getFont();
        Font themeDisplayFont = getFont(
                (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT),
                displayFont, defaultBaseFontSize);

        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.BLACK);
            dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047);

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

    DialCap cap = new DialCap();
    cap.setRadius(0.05);
    cap.setFillPaint(Color.BLACK);
    cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    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;

}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

protected JFreeChart makeDialChart(ChartModel chartModel, BasicDataModel data) {
    DialPlot chartBeansDialPlot = (DialPlot) chartModel.getPlot();

    org.jfree.chart.plot.dial.DialPlot jFreeDialPlot = new SquareDialPlot();

    final DefaultValueDataset dataset = new DefaultValueDataset();
    dataset.setValue(scaleNumber(data.getData().get(0), data.getScalingFactor()));

    jFreeDialPlot.setDataset(dataset);//from   www.j ava  2s  .  c o  m

    final DoubleLineDialFrame dialFrame = new DoubleLineDialFrame();
    dialFrame.setForegroundPaint(new Color(0x8d8d8d));
    dialFrame.setInnerForegroundPaint(new Color(0x5d5d5d));
    dialFrame.setStroke(new BasicStroke(2));
    dialFrame.setBackgroundPaint(Color.WHITE);
    jFreeDialPlot.setDialFrame(dialFrame);

    for (DialRange dialRange : chartBeansDialPlot.getScale()) {
        if (dialRange.getColor() != null) {
            SingleLineDialRange standarddialrange = new SingleLineDialRange(
                    dialRange.getMinValue().doubleValue(), dialRange.getMaxValue().doubleValue(),
                    new Color(0x00FFFFFF & dialRange.getColor()));
            standarddialrange.setInnerRadius(0.4D);
            jFreeDialPlot.addLayer(standarddialrange);
        }
    }

    double scaleMajorTickIncrement = (chartBeansDialPlot.getScale().getMaxValue().doubleValue()
            - chartBeansDialPlot.getScale().getMinValue().doubleValue()) / 5;
    FixedStandardDialScale standardDialScale = new FixedStandardDialScale(
            chartBeansDialPlot.getScale().getMinValue().doubleValue(),
            chartBeansDialPlot.getScale().getMaxValue().doubleValue(), -150.0, -240.0, scaleMajorTickIncrement,
            2);
    standardDialScale.setTickRadius(0.88D);
    standardDialScale.setTickLabelOffset(0.15D);
    standardDialScale
            .setTickLabelFont(ChartUtils.getFont("sans-serif", FontStyle.NORMAL, FontWeight.NORMAL, 10));
    standardDialScale.setTickLabelPaint(Color.BLACK);
    standardDialScale.setMajorTickLength(0.04);
    standardDialScale.setMajorTickPaint(Color.BLACK);
    standardDialScale.setMajorTickStroke(new BasicStroke(2));
    standardDialScale.setMinorTickLength(0.02);
    standardDialScale.setMinorTickPaint(new Color(0x8b8b8b));
    standardDialScale.setMinorTickStroke(new BasicStroke(1));
    jFreeDialPlot.addScale(0, standardDialScale);

    DialCap dialCap = new DialCap();
    dialCap.setRadius(0.06);
    dialCap.setFillPaint(new Color(0x636363));
    dialCap.setOutlinePaint(new Color(0x5d5d5d));
    dialCap.setOutlineStroke(new BasicStroke(2));
    jFreeDialPlot.setCap(dialCap);

    GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(0xfcfcfc), new Point(),
            new Color(0xd7d8da));
    DialBackground dialbackground = new DialBackground(gradientpaint); // specify Color here for no gradient
    dialbackground.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    jFreeDialPlot.setBackground(dialbackground);

    VariableStrokePointer pointer = new VariableStrokePointer();
    pointer.setRadius(0.9);
    pointer.setOutlineStroke(new BasicStroke(2));
    pointer.setWidthRadius(0.05);
    pointer.setFillPaint(new Color(0x636363));
    pointer.setOutlinePaint(new Color(0x5d5d5d));
    jFreeDialPlot.addPointer(pointer);

    DialValueIndicator dialValueIndicator = new DialValueIndicator(0);
    dialValueIndicator.setTemplateValue(chartBeansDialPlot.getScale().getMaxValue());
    dialValueIndicator.setFont(ChartUtils.getFont("Dialog", FontStyle.NORMAL, FontWeight.BOLD, 10));
    dialValueIndicator.setPaint(Color.BLACK);
    dialValueIndicator.setBackgroundPaint(Color.WHITE);
    dialValueIndicator.setOutlineStroke(new BasicStroke(1));
    dialValueIndicator.setOutlinePaint(new Color(0x8b8b8b));
    jFreeDialPlot.addLayer(dialValueIndicator);

    if ((chartBeansDialPlot.getAnnotation() != null) && (chartBeansDialPlot.getAnnotation().getText() != null)
            && (chartBeansDialPlot.getAnnotation().getText().trim().length() > 0)) {
        Font font = ChartUtils.getFont(chartBeansDialPlot.getAnnotation().getFontFamily(),
                chartBeansDialPlot.getAnnotation().getFontStyle(),
                chartBeansDialPlot.getAnnotation().getFontWeight(),
                chartBeansDialPlot.getAnnotation().getFontSize());
        if (font == null) {
            font = ChartUtils.getFont("sans-serif", FontStyle.NORMAL, FontWeight.NORMAL, 10);
        }
        DialTextAnnotation dialTextAnnotation = new DialTextAnnotation(
                chartBeansDialPlot.getAnnotation().getText().trim());
        dialTextAnnotation.setFont(font);
        dialTextAnnotation.setRadius(0.6);
        jFreeDialPlot.addLayer(dialTextAnnotation);
    }

    String title = "";
    if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null)
            && (chartModel.getTitle().getText().trim().length() > 0)) {
        title = chartModel.getTitle().getText();
    }

    JFreeChart chart = new JFreeChart(title, jFreeDialPlot);
    initChart(chart, chartModel);

    return chart;
}

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

/**
 *
 */// ww w  .j a  va 2s  .  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 ww .  j a v a 2  s .  c o  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;

}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *///from   w  ww  .  j a  v  a  2s  .c om
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    dialPlot.setDataset((ValueDataset) getDataset());
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(jrPlot.getBackcolor());
    dialPlot.setBackground(db);
    Range range = convertRange(jrPlot.getDataRange());
    int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7;
    StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270,
            (range.getUpperBound() - range.getLowerBound()) / (tickCount - 1), 15);
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    if (jrPlot.getTickLabelFont() != null) {
        scale.setTickLabelFont(fontUtil.getAwtFont(jrPlot.getTickLabelFont(), getLocale()));
    }
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.3f));
    scale.setMajorTickPaint(jrPlot.getTickColor());
    scale.setMinorTickPaint(jrPlot.getTickColor());

    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);

    // localizing the default tick label formatter
    scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale())));

    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 > 0) {
            colorStep = 255 / size;
        }
        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());

            Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0);

            StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(),
                    intervalRange.getUpperBound(),
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor());
            dialRange.setInnerRadius(0.41);
            dialRange.setOuterRadius(0.41);
            dialPlot.addLayer(dialRange);
        }
    }

    JRValueDisplay display = jrPlot.getValueDisplay();
    String displayVisibility = display != null && getChart().hasProperties()
            ? getChart().getPropertiesMap().getProperty(PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE)
            : "false";
    if (Boolean.valueOf(displayVisibility)) {
        DialValueIndicator dvi = new DialValueIndicator(0);
        // we need the transparent paint because null is not accepted
        dvi.setBackgroundPaint(TRANSPARENT_PAINT);
        //         dvi.setFont(fontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD));
        dvi.setOutlinePaint(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(PROPERTY_DIAL_LABEL)
            : null;

    if (label != null) {
        JRFont displayFont = display == null ? null : display.getFont();

        String[] textLines = label.split("\\n");
        for (int i = 0; i < textLines.length; i++) {
            DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
            if (displayFont != null) {
                dialAnnotation.setFont(fontUtil.getAwtFont(displayFont, getLocale()));
            }
            if (display != null && display.getColor() != null) {
                dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor());
            }
            dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    DialPointer needle = new DialPointer.Pointer();

    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, isShowLegend());

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

    return jfreeChart;

}

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

/**
 *
 *///from   ww w. j a v  a  2 s.c om
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    dialPlot.setDataset((ValueDataset) getDataset());
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(jrPlot.getBackcolor());
    dialPlot.setBackground(db);
    Range range = convertRange(jrPlot.getDataRange());
    //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));

    StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270,
            (range.getUpperBound() - range.getLowerBound()) / 6, 15);
    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(jrPlot.getTickColor());
    scale.setMinorTickPaint(jrPlot.getTickColor());

    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 > 0)
            colorStep = 255 / size;

        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = (JRMeterInterval) intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());

            Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0);

            StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(),
                    intervalRange.getUpperBound(),
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor());
            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)) {
        DialValueIndicator dvi = new DialValueIndicator(0);
        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);
        String[] textLines = label.split("\\n");
        for (int i = 0; i < textLines.length; i++) {
            DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
            dialAnnotation.setFont(themeDisplayFont);
            dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor());
            dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    DialPointer needle = new DialPointer.Pointer();

    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, isShowLegend());

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

    return jfreeChart;

}

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

/**
 *
 *///from ww w. j  a  va 2  s. com
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    dialPlot.setDataset((ValueDataset) getDataset());
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(jrPlot.getBackcolor());
    dialPlot.setBackground(db);
    Range range = convertRange(jrPlot.getDataRange());
    //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));

    StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270,
            (range.getUpperBound() - range.getLowerBound()) / 6, 15);
    scale.setTickRadius(0.9);
    scale.setTickLabelOffset(0.16);
    JRBaseFont font = new JRBaseFont();
    JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getTickLabelFont(), font);
    JRFontUtil.copyNonNullOwnProperties(jrPlot.getTickLabelFont(), font);
    font = new JRBaseFont(getChart(), font);
    scale.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale()));
    scale.setMajorTickStroke(new BasicStroke(1f));
    scale.setMinorTickStroke(new BasicStroke(0.3f));
    scale.setMajorTickPaint(jrPlot.getTickColor());
    scale.setMinorTickPaint(jrPlot.getTickColor());

    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 > 0)
            colorStep = 255 / size;

        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = (JRMeterInterval) intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());

            Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0);

            StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(),
                    intervalRange.getUpperBound(),
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor());
            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)) {
        DialValueIndicator dvi = new DialValueIndicator(0);
        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 = new JRBaseFont();
        JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getDisplayFont(), displayFont);
        JRFontUtil.copyNonNullOwnProperties(jrPlot.getValueDisplay().getFont(), displayFont);
        displayFont = new JRBaseFont(getChart(), displayFont);
        Font themeDisplayFont = JRFontUtil.getAwtFont(displayFont, getLocale());

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

    DialPointer needle = new DialPointer.Pointer();

    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, isShowLegend());

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

    return jfreeChart;

}

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

/**
 *
 *///from   w  w w.  j  a  v  a 2s . c  om
protected JFreeChart createDialChart() throws JRException {

    JRMeterPlot jrPlot = (JRMeterPlot) getPlot();

    // get data for diagrams
    DialPlot dialPlot = new DialPlot();
    dialPlot.setDataset((ValueDataset) getDataset());
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialPlot.setDialFrame(dialFrame);

    DialBackground db = new DialBackground(jrPlot.getBackcolor());
    dialPlot.setBackground(db);
    Range range = convertRange(jrPlot.getDataRange());
    //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound()));
    int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7;
    StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270,
            (range.getUpperBound() - range.getLowerBound()) / (tickCount - 1), 15);
    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(jrPlot.getTickColor());
    scale.setMinorTickPaint(jrPlot.getTickColor());

    scale.setTickLabelsVisible(true);
    scale.setFirstTickLabelVisible(true);

    // localizing the default tick label formatter
    scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale())));

    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 > 0)
            colorStep = 255 / size;

        for (int i = 0; i < size; i++) {
            JRMeterInterval interval = intervals.get(i);
            Range intervalRange = convertRange(interval.getDataRange());

            Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0);

            StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(),
                    intervalRange.getUpperBound(),
                    interval.getBackgroundColor() == null ? color : interval.getBackgroundColor());
            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)) {
        DialValueIndicator dvi = new DialValueIndicator(0);
        dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        //         dvi.setFont(getFontUtil().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);
        String[] textLines = label.split("\\n");
        for (int i = 0; i < textLines.length; i++) {
            DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]);
            dialAnnotation.setFont(themeDisplayFont);
            dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor());
            dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0);
            dialAnnotation.setAnchor(TextAnchor.CENTER);
            dialPlot.addLayer(dialAnnotation);
        }
    }

    DialPointer needle = new DialPointer.Pointer();

    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, isShowLegend());

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

    return jfreeChart;

}