Example usage for org.jfree.chart.plot.dial DialValueIndicator setOutlineStroke

List of usage examples for org.jfree.chart.plot.dial DialValueIndicator setOutlineStroke

Introduction

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

Prototype

public void setOutlineStroke(Stroke stroke) 

Source Link

Document

Sets the outline stroke and sends a DialLayerChangeEvent to all registered listeners.

Usage

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 ww  w .jav a 2s.  co  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:org.pentaho.chart.plugin.jfreechart.chart.dial.JFreeDialChartGenerator.java

public void setDialValueIndicator(ChartDocument chartDocument, DialPlot dialPlot) {

    // ~ params begin
    Font valueIndicatorFont = new Font("Dialog", Font.BOLD, 14); //$NON-NLS-1$
    Color valueIndicatorPaint = Color.black;
    Color valueIndicatorBackgroundPaint = Color.white;
    Stroke valueIndicatorOutlineStroke = new BasicStroke(1.0f);
    Color valueIndicatorOutlinePaint = Color.blue;
    // ~ params end

    ChartElement valIndicatorElement = getUniqueElement(chartDocument, DIALVALUEINDICATOR);
    Color valIndicatorColorTmp = ColorFactory.getInstance().getColor(valIndicatorElement);
    if (valIndicatorColorTmp != null) {
        valueIndicatorPaint = valIndicatorColorTmp;
    }/* w w  w.j a  va  2s  .c o  m*/

    Color valIndicatorBgColorTmp = ColorFactory.getInstance().getColor(valIndicatorElement,
            BorderStyleKeys.BACKGROUND_COLOR);
    if (valIndicatorBgColorTmp != null) {
        valueIndicatorBackgroundPaint = valIndicatorBgColorTmp;
    }

    final BasicStroke borderStyleStroke = StrokeFactory.getInstance().getBorderStroke(valIndicatorElement);
    if (borderStyleStroke != null) {
        valueIndicatorOutlineStroke = borderStyleStroke;
    }

    Color valIndicatorBorderColorTmp = ColorFactory.getInstance().getColor(valIndicatorElement,
            BorderStyleKeys.BORDER_TOP_COLOR);
    if (valIndicatorBorderColorTmp != null) {
        valueIndicatorOutlinePaint = valIndicatorBorderColorTmp;
    }

    Font valIndicatorFontTmp = JFreeChartUtils.getFont(valIndicatorElement);
    if (valIndicatorFontTmp != null) {
        valueIndicatorFont = valIndicatorFontTmp;
    }

    DialValueIndicator dialValueIndicator = new DialValueIndicator(0);

    // begin code to determine the size of the value indicator box 
    ChartElement scaleElement = getUniqueElement(chartDocument, SCALE);
    if (scaleElement != null) {

        double scaleUpperBound = Double.parseDouble(scaleElement.getAttribute(UPPERBOUND).toString());
        double scaleLowerBound = Double.parseDouble(scaleElement.getAttribute(LOWERBOUND).toString());

        if (Math.abs(scaleUpperBound) > Math.abs(scaleLowerBound)) {
            dialValueIndicator.setTemplateValue(scaleUpperBound);
        } else {
            dialValueIndicator.setTemplateValue(scaleLowerBound);
        }
    }
    // end code to determine the size of the value indicator box

    dialValueIndicator.setFont(valueIndicatorFont);
    dialValueIndicator.setPaint(valueIndicatorPaint);
    dialValueIndicator.setBackgroundPaint(valueIndicatorBackgroundPaint);
    dialValueIndicator.setOutlineStroke(valueIndicatorOutlineStroke);
    dialValueIndicator.setOutlinePaint(valueIndicatorOutlinePaint);
    dialPlot.addLayer(dialValueIndicator);
}