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

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

Introduction

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

Prototype

public void setTemplateValue(Number value) 

Source Link

Document

Sets the template value and sends a DialLayerChangeEvent to all registered listeners.

Usage

From source file:meter_rpm.Stackoverflow.java

private ChartPanel buildDialPlot(int minimumValue, int maximumValue, int majorTickGap) {

    DialPlot plot = new DialPlot();
    plot.setView(0.0D, 0.0D, 1.0D, 1.0D);
    plot.setDataset(0, dataset0);/* w  w  w  .  ja  v  a  2s  .c  o  m*/
    plot.setDataset(1, dataset1);

    plot.setDialFrame(new StandardDialFrame());

    DialTextAnnotation dialtextannotation = new DialTextAnnotation("RPM");
    dialtextannotation.setFont(new Font("Dialog", 1, 12));
    dialtextannotation.setRadius(0.69999999999999996D);
    plot.addLayer(dialtextannotation);

    // value indicator uses the real data set
    //plot.addLayer(new DialValueIndicator(0));

    DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
    dialvalueindicator.setFont(new Font("Dialog", Font.BOLD, 12));
    dialvalueindicator.setOutlinePaint(Color.YELLOW);
    dialvalueindicator.setRadius(0.6D);
    dialvalueindicator.setAngle(-90D);
    dialvalueindicator.setTemplateValue(1000);
    plot.addLayer(dialvalueindicator);

    org.jfree.chart.plot.dial.DialPointer.Pin pin1 = new org.jfree.chart.plot.dial.DialPointer.Pin(1);
    pin1.setRadius(0.55000000000000004D);
    plot.addPointer(pin1);

    // needle uses constrained data set
    plot.addLayer(new DialPointer.Pointer(0));

    StandardDialScale scale = new StandardDialScale(0d, 6000, -110, -320, majorTickGap, 4);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.20);
    scale.setTickLabelFormatter(new DecimalFormat("####"));

    plot.addScale(0, scale);

    StandardDialScale standarddialscale1 = new StandardDialScale(0D, 30D, -120D, -300D, 5D, 4);
    standarddialscale1.setTickRadius(0.5D);
    standarddialscale1.setTickLabelOffset(0.14999999999999999D);
    standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
    standarddialscale1.setMajorTickPaint(Color.RED);
    standarddialscale1.setMinorTickPaint(Color.RED);
    plot.addScale(1, standarddialscale1);

    plot.mapDatasetToScale(1, 1);

    JFreeChart jfreechart = new JFreeChart(plot);
    jfreechart.setTitle("ENGINE RPM & MANIFOLD PRESSURE");
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(400, 400));

    return chartpanel;
}

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 av  a 2 s.com*/

    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;
    }//from   w  ww.j a va 2  s  . 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);
}