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

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

Introduction

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

Prototype

public void setNumberFormat(NumberFormat formatter) 

Source Link

Document

Sets the formatter used to format the value and sends a DialLayerChangeEvent to all registered listeners.

Usage

From source file:org.cyberoam.iview.charts.MeterChart.java

/**
 * This method generates JFreeChart instance for Meter chart with dial port and iView customization.
 * @param reportID/*from   www.j a v  a  2  s.c o m*/
 * @param rsw
 * @param request
 * @return
 */
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    ReportColumnBean reportColumnBean = null;
    GraphBean graphBean = null;
    try {
        DefaultValueDataset data = null;
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        rsw.first();
        double used = Double.parseDouble(rsw.getString(yColumnDBname));
        data = new DefaultValueDataset(100 - used);
        DialPlot plot = new DialPlot(data);
        chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

        chart.setBackgroundPaint(Color.white);
        int imgWidth = graphBean.getWidth();
        int imgHeight = graphBean.getHeight();
        if (request != null && request.getParameter("imgwidth") != null
                && !"".equalsIgnoreCase(request.getParameter("imgwidth"))
                && !"null".equalsIgnoreCase(request.getParameter("imgwidth"))) {
            imgWidth = Integer.parseInt(request.getParameter("imgwidth"));
        }
        if (request != null && request.getParameter("imgheight") != null
                && !"".equalsIgnoreCase(request.getParameter("imgheight"))
                && !"null".equalsIgnoreCase(request.getParameter("imgheight"))) {
            imgHeight = Integer.parseInt(request.getParameter("imgheight"));
        }
        plot.setView((1 - ((double) imgWidth / (double) imgHeight)) / 2, plot.getViewY(),
                ((double) imgWidth / (double) imgHeight), plot.getViewHeight());
        StandardDialFrame dialFrame = new StandardDialFrame();
        dialFrame.setBackgroundPaint(new Color(54, 73, 109));
        dialFrame.setRadius(0.8);
        dialFrame.setStroke(new BasicStroke(0));
        plot.setDialFrame(dialFrame);
        GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
                new Color(196, 210, 219));
        DialBackground db = new DialBackground(gp);
        db.setGradientPaintTransformer(
                new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
        plot.setBackground(db);

        DialValueIndicator dvi = new DialValueIndicator(0);
        dvi.setRadius(0.55);
        dvi.setBackgroundPaint(gp);
        dvi.setNumberFormat(new DecimalFormat("###"));
        dvi.setFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        dvi.setOutlinePaint(Color.lightGray);
        plot.addLayer(dvi);

        StandardDialScale scale = new StandardDialScale(0, 100, -120, -300, 10, 4);
        scale.setTickRadius(0.75);
        scale.setTickLabelOffset(0.15);
        scale.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 9));
        plot.addScale(0, scale);

        StandardDialRange range = new StandardDialRange(0.0, 50.0, Color.green);
        range.setInnerRadius(0.35);
        range.setOuterRadius(0.38);
        plot.addLayer(range);

        StandardDialRange range2 = new StandardDialRange(50.0, 75.0, Color.yellow);
        range2.setInnerRadius(0.35);
        range2.setOuterRadius(0.38);
        plot.addLayer(range2);

        StandardDialRange range3 = new StandardDialRange(75.0, 100.0, Color.red);
        range3.setInnerRadius(0.35);
        range3.setOuterRadius(0.38);
        plot.addLayer(range3);

        DialPointer needle = new DialPointer.Pointer();
        needle.setRadius(0.55);
        plot.addLayer(needle);

        DialCap cap = new DialCap();
        cap.setRadius(0.05);
        plot.setCap(cap);

    } catch (Exception e) {
        CyberoamLogger.appLog.debug("MeterChart=>Exception : " + e, e);
    }
    return chart;
}

From source file:com.romraider.logger.ecu.ui.handler.dash.SmallDialGaugeStyle.java

protected JFreeChart buildChart() {
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);/*from w ww.  j a v a2 s  . c  o m*/
    plot.setDataset(0, current);
    plot.setDataset(1, max);
    plot.setDataset(2, min);
    DialFrame dialFrame = new StandardDialFrame();
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(VERTICAL));
    plot.setBackground(db);

    unitsLabel.setFont(new Font(Font.DIALOG, BOLD, 14));
    unitsLabel.setRadius(0.7);
    unitsLabel.setLabel(loggerData.getSelectedConvertor().getUnits());
    plot.addLayer(unitsLabel);

    DecimalFormat format = new DecimalFormat(loggerData.getSelectedConvertor().getFormat());

    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setNumberFormat(format);
    plot.addLayer(dvi);

    EcuDataConvertor convertor = loggerData.getSelectedConvertor();
    GaugeMinMax minMax = convertor.getGaugeMinMax();
    StandardDialScale scale = new StandardDialScale(minMax.min, minMax.max, 225.0, -270.0, minMax.step, 5);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font(Font.DIALOG, PLAIN, 12));
    scale.setTickLabelFormatter(format);
    plot.addScale(0, scale);
    plot.addScale(1, scale);
    plot.addScale(2, scale);

    StandardDialRange range = new StandardDialRange(rangeLimit(minMax, 0.75), minMax.max, RED);
    range.setInnerRadius(0.52);
    range.setOuterRadius(0.55);
    plot.addLayer(range);

    StandardDialRange range2 = new StandardDialRange(rangeLimit(minMax, 0.5), rangeLimit(minMax, 0.75), ORANGE);
    range2.setInnerRadius(0.52);
    range2.setOuterRadius(0.55);
    plot.addLayer(range2);

    StandardDialRange range3 = new StandardDialRange(minMax.min, rangeLimit(minMax, 0.5), GREEN);
    range3.setInnerRadius(0.52);
    range3.setOuterRadius(0.55);
    plot.addLayer(range3);

    DialPointer needleCurrent = new DialPointer.Pointer(0);
    plot.addLayer(needleCurrent);

    DialPointer needleMax = new DialPointer.Pin(1);
    needleMax.setRadius(0.84);
    ((DialPointer.Pin) needleMax).setPaint(RED);
    ((DialPointer.Pin) needleMax).setStroke(new BasicStroke(1.5F));
    plot.addLayer(needleMax);

    DialPointer needleMin = new DialPointer.Pin(2);
    needleMin.setRadius(0.84);
    ((DialPointer.Pin) needleMin).setPaint(BLUE);
    ((DialPointer.Pin) needleMin).setStroke(new BasicStroke(1.5F));
    plot.addLayer(needleMin);

    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(loggerData.getName());

    return chart;
}

From source file:com.bdb.weather.display.current.Hygrometer.java

private ChartViewer createChartElements() {
    humidityPlot.addLayer(/*from  ww w.  ja  v a2s. c om*/
            new DialBackground(new GradientPaint(0.0f, 0.0f, Color.LIGHT_GRAY, 100.0f, 0.0f, Color.blue)));
    StandardDialScale scale = new StandardDialScale(Humidity.MIN_HUMIDITY.get(), Humidity.MAX_HUMIDITY.get(),
            240.0, -300.0, 10.0, 9);
    scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN));
    scale.setTickRadius(.9);
    scale.setTickLabelFormatter(new DecimalFormat("#"));
    scale.setTickLabelOffset(.2);
    scale.setTickLabelPaint(Color.BLACK);
    humidityPlot.addScale(0, scale);
    humidityPlot.setDialFrame(new StandardDialFrame());

    DialValueIndicator valueInd = new DialValueIndicator(0);
    valueInd.setNumberFormat(new DecimalFormat("# '%rH'"));
    Color c = new Color(255, 255, 255, 0);
    valueInd.setBackgroundPaint(c);
    valueInd.setOutlinePaint(c);
    valueInd.setPaint(Color.cyan);
    humidityPlot.addLayer(valueInd);

    double angle = valueInd.getAngle();
    double radius = valueInd.getRadius();

    trendAnnotation.setPaint(Color.cyan);
    trendAnnotation.setAngle(angle);
    trendAnnotation.setRadius(radius + .1);
    humidityPlot.addLayer(trendAnnotation);

    DialPointer.Pointer pointer = new DialPointer.Pointer(0);
    humidityPlot.addPointer(pointer);

    DialCap cap = new DialCap();
    cap.setRadius(cap.getRadius() * 1.5);
    humidityPlot.setCap(cap);

    range = new StandardDialRange(Humidity.MIN_HUMIDITY.get(), Humidity.MAX_HUMIDITY.get(), Color.BLACK);
    range.setInnerRadius(.40);
    range.setOuterRadius(.45);
    range.setScaleIndex(0);
    humidityPlot.addLayer(range);

    JFreeChart chart = new JFreeChart(humidityPlot);
    chart.setBackgroundPaint(Color.GRAY);

    ChartViewer chartViewer = new ChartViewer(chart);
    //chartViewer.setMinHeight(100);
    //chartViewer.setMinWidth(100);
    //chartViewer.setMaxHeight(400);
    //chartViewer.setMaxWidth(400);
    //chartViewer.setBackground(Color.GRAY);
    return chartViewer;
}

From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java

protected JFreeChart buildChart() {
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);//  w  ww  .  java  2 s  .c  o m
    plot.setDataset(0, current);
    plot.setDataset(1, max);
    plot.setDataset(2, min);
    DialFrame dialFrame = new StandardDialFrame();
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(VERTICAL));
    plot.setBackground(db);

    unitsLabel.setFont(new Font(Font.DIALOG, BOLD, 15));
    unitsLabel.setRadius(0.7);
    unitsLabel.setLabel(loggerData.getSelectedConvertor().getUnits());
    plot.addLayer(unitsLabel);

    DecimalFormat format = new DecimalFormat(loggerData.getSelectedConvertor().getFormat());

    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setNumberFormat(format);
    plot.addLayer(dvi);

    EcuDataConvertor convertor = loggerData.getSelectedConvertor();
    GaugeMinMax minMax = convertor.getGaugeMinMax();
    StandardDialScale scale = new StandardDialScale(minMax.min, minMax.max, 225.0, -270.0, minMax.step, 5);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font(Font.DIALOG, PLAIN, 12));
    scale.setTickLabelFormatter(format);
    plot.addScale(0, scale);
    plot.addScale(1, scale);
    plot.addScale(2, scale);

    StandardDialRange range = new StandardDialRange(rangeLimit(minMax, 0.75), minMax.max, RED);
    range.setInnerRadius(0.52);
    range.setOuterRadius(0.55);
    plot.addLayer(range);

    StandardDialRange range2 = new StandardDialRange(rangeLimit(minMax, 0.5), rangeLimit(minMax, 0.75), ORANGE);
    range2.setInnerRadius(0.52);
    range2.setOuterRadius(0.55);
    plot.addLayer(range2);

    StandardDialRange range3 = new StandardDialRange(minMax.min, rangeLimit(minMax, 0.5), GREEN);
    range3.setInnerRadius(0.52);
    range3.setOuterRadius(0.55);
    plot.addLayer(range3);

    DialPointer needleCurrent = new DialPointer.Pointer(0);
    plot.addLayer(needleCurrent);

    DialPointer needleMax = new DialPointer.Pin(1);
    needleMax.setRadius(0.84);
    ((DialPointer.Pin) needleMax).setPaint(RED);
    ((DialPointer.Pin) needleMax).setStroke(new BasicStroke(1.5F));
    plot.addLayer(needleMax);

    DialPointer needleMin = new DialPointer.Pin(2);
    needleMin.setRadius(0.84);
    ((DialPointer.Pin) needleMin).setPaint(BLUE);
    ((DialPointer.Pin) needleMin).setStroke(new BasicStroke(1.5F));
    plot.addLayer(needleMin);

    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(loggerData.getName());

    return chart;
}

From source file:com.bdb.weather.display.current.Barometer.java

private ChartViewer createChartElements(Pressure min, Pressure max) {
    Color backgroundDialColor = StageUtilities
            .toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_DIAL_COLOR));
    Paint backgroundPaint = new GradientPaint(0.0f, 0.0f, Color.LIGHT_GRAY, 100.0f, 0.0f, backgroundDialColor);
    DialBackground background = new DialBackground(backgroundPaint);
    plot.addLayer(background);// w  ww. ja v  a  2 s.  c  o m
    double dialTickIncrements = .2;
    switch (Pressure.getDefaultUnit()) {
    case IN_HG:
        dialTickIncrements = .2;
        break;
    case HECTO_PASCAL:
    case MILLIBAR:
        dialTickIncrements = 10.0;
        break;
    }

    scale = new StandardDialScale(min.get(), max.get(), 240.0, -300.0, dialTickIncrements, 10);
    scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN));
    scale.setTickRadius(.9);
    scale.setTickLabelFormatter(Pressure.getDefaultFormatter());
    scale.setTickLabelOffset(.25);
    scale.setTickLabelPaint(
            StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_SCALE_TEXT)));
    scale.setMajorTickPaint(
            StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_SCALE_TICK)));
    scale.setMinorTickPaint(
            StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_SCALE_TICK)));
    plot.addScale(0, scale);
    plot.setDialFrame(new StandardDialFrame());
    DialValueIndicator valueInd = new DialValueIndicator(0);
    //
    // Set background and outline paint to be completely transparent so they do not show at all
    //
    valueInd.setBackgroundPaint(new Color(255, 255, 255, 0));
    valueInd.setOutlinePaint(new Color(255, 255, 255, 0));
    valueInd.setPaint(StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_VALUE)));
    valueInd.setNumberFormat(Pressure.getDefaultUnit().getFormatterWithUnit());
    plot.addLayer(valueInd);

    double angle = valueInd.getAngle();
    double radius = valueInd.getRadius();

    trendAnnotation.setPaint(StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_VALUE)));
    trendAnnotation.setAngle(angle);
    trendAnnotation.setRadius(radius + .1);
    plot.addLayer(trendAnnotation);

    DialPointer.Pointer pointer = new DialPointer.Pointer(0);
    plot.addPointer(pointer);

    DialCap cap = new DialCap();
    cap.setRadius(cap.getRadius() * 1.5);
    plot.setCap(cap);

    range = new StandardDialRange(0.0, 360.0,
            StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_VALUE_RANGE)));
    range.setInnerRadius(.40);
    range.setOuterRadius(.45);
    range.setScaleIndex(0);
    plot.addLayer(range);

    JFreeChart chart = new JFreeChart(plot);
    chart.setBackgroundPaint(
            StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_BACKGROUND)));

    ChartViewer chartViewer = new ChartViewer(chart);
    chartViewer.setMinHeight(200);
    chartViewer.setMinWidth(200);
    chartViewer.setMaxHeight(10000);
    chartViewer.setMaxWidth(10000);

    //chartViewer.setBorder(new BevelBorder(BevelBorder.RAISED));

    return chartViewer;
}

From source file:se.technipelago.weather.chart.Generator.java

private void createWindDial(float speed, float high, final String filename) throws IOException {
    ValueDataset dataset1 = new DefaultValueDataset(speed);
    ValueDataset dataset2 = new DefaultValueDataset(high);

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);//from   ww w  .  j  a v a2  s  . c  om
    plot.setDataset(0, dataset1);
    plot.setDataset(1, dataset2);
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.darkGray);
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(db);

    // Wind Speed
    DialTextAnnotation annotation1 = new DialTextAnnotation("m/s");
    annotation1.setFont(new Font("Dialog", Font.BOLD, 10));
    annotation1.setRadius(0.76);

    plot.addLayer(annotation1);

    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setFont(new Font("Dialog", Font.PLAIN, 9));
    dvi.setOutlinePaint(Color.darkGray);
    //dvi.setBackgroundPaint(new Color(0xee, 0xee, 0xf6));
    NumberFormat fmt = new DecimalFormat("#");
    fmt.setMaximumFractionDigits(1);
    fmt.setMinimumIntegerDigits(1);
    dvi.setNumberFormat(fmt);
    dvi.setRadius(0.71);
    dvi.setAngle(-89.0); // -103
    dvi.setInsets(new RectangleInsets(0.0, 2.0, 0.0, 2.0)); // top, left, bottom, right
    plot.addLayer(dvi);

    StandardDialScale scale = new StandardDialScale(0, 20, -120, -300, 1, 0);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    NumberFormat fmt3 = new DecimalFormat("#");
    fmt3.setMaximumFractionDigits(0);
    scale.setTickLabelFormatter(fmt3);
    plot.addScale(0, scale);

    // Add needles.
    // To make the average speed needle the front-most needle,
    // it must be added after high speed needle.
    // High speed needle.
    DialPointer needle2 = new DialPointer.Pin(1);
    needle2.setRadius(0.62);
    plot.addLayer(needle2);

    // Average speed needle.
    DialPointer needle = new DialPointer.Pointer(0);
    Color darkGreen = new Color(0x15, 0x49, 0x1f);
    ((DialPointer.Pointer) needle).setFillPaint(darkGreen);
    plot.addLayer(needle);

    // Add a cap at the dial center.
    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    //TextTitle title = new TextTitle("Vindhastighet", new Font("Dialog", Font.BOLD, 12));
    //title.setPaint(Color.DARK_GRAY);
    //chart.setTitle(title);
    chart.setBackgroundPaint(VERY_LIGHT_GRAY);

    OutputStream out = null;
    try {
        out = new FileOutputStream(outputDir != null ? outputDir + "/" + filename : filename);
        ChartUtilities.writeChartAsPNG(out, chart, DIAL_WIDTH, DIAL_HEIGHT);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:se.technipelago.weather.chart.Generator.java

private void createTemperatureDial(float temperature, int humidity, final String filename) throws IOException {
    ValueDataset dataset1 = new DefaultValueDataset(temperature);
    ValueDataset dataset2 = new DefaultValueDataset(humidity);

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);/* ww  w.  j av a2 s.  c o  m*/
    plot.setDataset(0, dataset1);
    plot.setDataset(1, dataset2);
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.darkGray);
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(db);

    // Temperature
    DialTextAnnotation annotation1 = new DialTextAnnotation("\u00B0C");
    annotation1.setFont(new Font("Dialog", Font.BOLD, 10));
    annotation1.setRadius(0.76);

    plot.addLayer(annotation1);

    // Humidity
    DialTextAnnotation annotation2 = new DialTextAnnotation("%");
    annotation2.setFont(new Font("Dialog", Font.BOLD, 10));
    annotation2.setPaint(Color.blue);
    annotation2.setRadius(0.4);

    plot.addLayer(annotation2);

    // Temperature
    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setFont(new Font("Dialog", Font.PLAIN, 9));
    dvi.setOutlinePaint(Color.darkGray);
    //dvi.setBackgroundPaint(new Color(0xee, 0xee, 0xf6));
    NumberFormat fmt = new DecimalFormat("#");
    fmt.setMaximumFractionDigits(1);
    fmt.setMinimumIntegerDigits(1);
    dvi.setNumberFormat(fmt);
    dvi.setRadius(0.71);
    dvi.setAngle(-88.0); // -103
    dvi.setInsets(new RectangleInsets(0.0, 8.0, 0.0, 2.0)); // top, left, bottom, right
    plot.addLayer(dvi);

    StandardDialScale scale = new StandardDialScale(-30, 30, -120, -300, 5, 4);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    NumberFormat fmt3 = new DecimalFormat("#");
    fmt3.setMaximumFractionDigits(0);
    scale.setTickLabelFormatter(fmt3);
    plot.addScale(0, scale);

    // Humidity
    DialValueIndicator dvi2 = new DialValueIndicator(1);
    dvi2.setFont(new Font("Dialog", Font.PLAIN, 9));
    dvi2.setOutlinePaint(Color.blue);
    //dvi2.setBackgroundPaint(new Color(0xee, 0xee, 0xf6));
    NumberFormat fmt2 = new DecimalFormat("#");
    fmt2.setMaximumFractionDigits(0);
    dvi2.setNumberFormat(fmt2);

    dvi2.setRadius(0.59);
    dvi2.setAngle(-90.0); // -77
    dvi2.setInsets(new RectangleInsets(0.0, 1.0, 0.0, 1.0));
    plot.addLayer(dvi2);

    StandardDialScale scale2 = new StandardDialScale(0, 100, -120, -300, 10, 4);
    scale2.setTickRadius(0.50);
    scale2.setTickLabelOffset(0.15);
    scale2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 9));
    scale2.setTickLabelFormatter(fmt3);
    scale2.setMajorTickPaint(Color.blue);
    plot.addScale(1, scale2);
    plot.mapDatasetToScale(1, 1);

    // Add needles.
    // To make the temperature needle the front-most needle,
    // it must be added after humidity needle.
    // Humidity needle.
    DialPointer needle2 = new DialPointer.Pin(1);
    needle2.setRadius(0.50);
    plot.addLayer(needle2);

    // Temperature needle.
    DialPointer needle = new DialPointer.Pointer(0);
    Color darkGreen = new Color(0x15, 0x49, 0x1f);
    ((DialPointer.Pointer) needle).setFillPaint(darkGreen);
    plot.addLayer(needle);

    // Add a cap at the dial center.
    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    //TextTitle title = new TextTitle("Temperatur/luftfuktighet", new Font("Dialog", Font.BOLD, 12));
    //title.setPaint(Color.DARK_GRAY);
    //chart.setTitle(title);
    chart.setBackgroundPaint(VERY_LIGHT_GRAY);

    OutputStream out = null;
    try {
        out = new FileOutputStream(outputDir != null ? outputDir + "/" + filename : filename);
        ChartUtilities.writeChartAsPNG(out, chart, DIAL_WIDTH, DIAL_HEIGHT);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

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

/**
 *
 *///  www .ja  va2s .c  o m
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   w ww  .ja va  2 s.  c  o  m*/
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. ja va  2s.c  o m*/
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;

}