Example usage for org.jfree.chart.plot ThermometerPlot setValuePaint

List of usage examples for org.jfree.chart.plot ThermometerPlot setValuePaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot ThermometerPlot setValuePaint.

Prototype

public void setValuePaint(Paint paint) 

Source Link

Document

Sets the paint used to display the current value and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.sonar.plugins.ral.GaugeChart.java

@Override
protected Plot getPlot(ChartParameters params) {
    ThermometerPlot plot = new ThermometerPlot(createDataset(params));

    plot.setGap(1);//from   www  .j  a va  2  s  . co  m

    plot.setRange(0, 1);
    plot.setSubrange(0, 0, 1);

    plot.setSubrangePaint(0, Color.decode("#ffffff"));
    plot.setSubrangePaint(1, Color.decode("#ffffff"));
    plot.setSubrangePaint(2, Color.decode("#ffffff"));

    plot.setMercuryPaint(Color.decode("#dddddd"));
    plot.setThermometerPaint(Color.decode("#aaaaaa"));
    plot.setValuePaint(Color.decode("#333333"));

    plot.setUseSubrangePaint(false);
    plot.setUnits(ThermometerPlot.UNITS_NONE);
    plot.setBulbRadius(15);
    plot.setColumnRadius(6);

    NumberAxis axis = new NumberAxis();
    axis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    plot.setRangeAxis(axis);
    plot.setValueLocation(ThermometerPlot.NONE);

    return plot;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.Thermometer.java

/**
 * Creates a chart of type thermometer./*  www. ja  v  a 2 s .com*/
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart thermometer.
 */

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    Dataset dataset = (Dataset) datasets.getDatasets().get("1");

    ThermometerPlot plot = new ThermometerPlot((ValueDataset) dataset);
    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setPadding(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Color.lightGray);
    plot.setGap(3);
    plot.setValueLocation(3);
    plot.setValuePaint(labelsValueStyle.getColor());
    plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

    plot.setRange(lower, upper);

    if (units.equalsIgnoreCase(FAHRENHEIT))
        plot.setUnits(ThermometerPlot.UNITS_FAHRENHEIT);
    else if (units.equalsIgnoreCase(CELCIUS))
        plot.setUnits(ThermometerPlot.UNITS_CELCIUS);
    else if (units.equalsIgnoreCase(KELVIN))
        plot.setUnits(ThermometerPlot.UNITS_KELVIN);
    else
        plot.setUnits(ThermometerPlot.UNITS_NONE);

    // set subranges   
    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval subrange = (KpiInterval) iterator.next();
        int range = 0;
        if (subrange.getLabel().equalsIgnoreCase(NORMAL))
            range = (ThermometerPlot.NORMAL);
        else if (subrange.getLabel().equalsIgnoreCase(WARNING))
            range = (ThermometerPlot.WARNING);
        else if (subrange.getLabel().equalsIgnoreCase(CRITICAL))
            range = (ThermometerPlot.CRITICAL);

        plot.setSubrange(range, subrange.getMin(), subrange.getMax());
        if (subrange.getColor() != null) {
            plot.setSubrangePaint(range, subrange.getColor());
        }
        //plot.setDisplayRange(subrange.getRange(), subrange.getLower(), subrange.getUpper());   
    }
    //plot.setFollowDataInSubranges(true);
    logger.debug("OUT");

    return chart;
}

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

/**
 *
 *///from w  w  w . ja  v a  2s .  co m
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());
    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(chartPlot);

    // Set the generic options
    configureChart(jfreeChart, getPlot());
    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);

    Range range = convertRange(jrPlot.getDataRange());

    if (range != null) {
        // Set the boundary of the thermomoter
        chartPlot.setLowerBound(range.getLowerBound());
        chartPlot.setUpperBound(range.getUpperBound());
    }
    chartPlot.setGap(0);

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    List seriesPaints = (List) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS);

    Paint paint = (jrPlot.getMercuryColor() != null ? (Paint) jrPlot.getMercuryColor()
            : (Paint) seriesPaints.get(0));
    chartPlot.setMercuryPaint(paint);

    chartPlot.setThermometerPaint(THERMOMETER_COLOR);
    chartPlot.setThermometerStroke(new BasicStroke(2f));
    chartPlot.setOutlineVisible(false);
    chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD));

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }
        if (display.getMask() != null) {
            chartPlot.setValueFormat(new DecimalFormat(display.getMask()));
        }
        if (display.getFont() != null) {
            //            chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD));
        }
    }

    // Set the location of where the value is displayed
    // Set the location of where the value is displayed
    ValueLocationEnum valueLocation = jrPlot.getValueLocationValue();
    switch (valueLocation) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    return jfreeChart;
}

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

/**
 *
 *//*ww w .  j a  v a2  s  .c  om*/
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());
    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(chartPlot);

    // Set the generic options
    configureChart(jfreeChart, getPlot());
    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);

    Range range = convertRange(jrPlot.getDataRange());

    if (range != null) {
        // Set the boundary of the thermomoter
        chartPlot.setLowerBound(range.getLowerBound());
        chartPlot.setUpperBound(range.getUpperBound());
    }
    chartPlot.setGap(0);

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    Paint paint = (jrPlot.getMercuryColor() != null ? (Paint) jrPlot.getMercuryColor()
            : (Paint) ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(0));
    chartPlot.setMercuryPaint(paint);

    chartPlot.setThermometerPaint(THERMOMETER_COLOR);
    chartPlot.setThermometerStroke(new BasicStroke(2f));
    chartPlot.setOutlineVisible(false);
    chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD));

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }
        if (display.getMask() != null) {
            chartPlot.setValueFormat(new DecimalFormat(display.getMask()));
        }
        if (display.getFont() != null) {
            //            chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD));
        }
    }

    // Set the location of where the value is displayed
    ValueLocationEnum valueLocation = jrPlot.getValueLocationValue();
    switch (valueLocation) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    return jfreeChart;

}

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

@Override
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());

    ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
    // setting localized range axis formatters
    chartPlot.getRangeAxis().setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));

    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null,
            chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend());

    // Set the generic options
    configureChart(jfreeChart, getPlot());
    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);//from   w  w  w . j av  a  2 s  .  co  m

    Range range = convertRange(jrPlot.getDataRange());

    if (range != null) {
        // Set the boundary of the thermomoter
        chartPlot.setLowerBound(range.getLowerBound());
        chartPlot.setUpperBound(range.getUpperBound());
    }
    chartPlot.setGap(0);

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    @SuppressWarnings("unchecked")
    List<Paint> seriesPaints = (List<Paint>) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SERIES_COLORS);

    Paint paint = jrPlot.getMercuryColor();
    if (paint != null) {
        chartPlot.setUseSubrangePaint(false);
    } else {
        //it has no effect, but is kept for backward compatibility reasons
        paint = seriesPaints.get(0);
    }

    chartPlot.setMercuryPaint(paint);

    chartPlot.setThermometerPaint(THERMOMETER_COLOR);
    chartPlot.setThermometerStroke(new BasicStroke(2f));
    chartPlot.setOutlineVisible(false);
    chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD));

    // localizing the default format, can be overridden by display.getMask()
    chartPlot.setValueFormat(NumberFormat.getNumberInstance(getLocale()));

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }
        if (display.getMask() != null) {
            chartPlot.setValueFormat(
                    new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale())));
        }
        if (display.getFont() != null) {
            //            chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD));
        }
    }

    // Set the location of where the value is displayed
    // Set the location of where the value is displayed
    ValueLocationEnum valueLocation = jrPlot.getValueLocationValue();
    switch (valueLocation) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    return jfreeChart;
}

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

/**
 * Build and run a thermometer chart.  JFreeChart thermometer charts have some
 * limitations.  They always have a maximum of three ranges, and the colors of those
 * ranges seems to be fixed.//from  www  .j a v a2s.  c  o  m
 *
 * @param evaluation current expression evaluation phase
 * @throws JRException
 */
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());

    Range range = convertRange(jrPlot.getDataRange());

    // Set the boundary of the thermomoter
    chartPlot.setLowerBound(range.getLowerBound());
    chartPlot.setUpperBound(range.getUpperBound());

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    Color color = jrPlot.getMercuryColor();
    if (color != null) {
        chartPlot.setMercuryPaint(color);
    }

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }
        if (display.getMask() != null) {
            chartPlot.setValueFormat(new DecimalFormat(display.getMask()));
        }
        if (display.getFont() != null) {
            //            chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()));
        }
    }

    // Set the location of where the value is displayed
    ValueLocationEnum valueLocation = jrPlot.getValueLocationValue();
    switch (valueLocation) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(chartPlot);

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

    return jfreeChart;
}

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

/**
 * Build and run a thermometer chart.  JFreeChart thermometer charts have some
 * limitations.  They always have a maximum of three ranges, and the colors of those
 * ranges seems to be fixed.//w  w  w.j a va  2s  .  c o m
 */
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());

    ChartUtil chartUtil = ChartUtil.getInstance(chartContext.getJasperReportsContext());
    // setting localized range axis formatters
    chartPlot.getRangeAxis().setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));

    Range range = convertRange(jrPlot.getDataRange());

    // Set the boundary of the thermomoter
    chartPlot.setLowerBound(range.getLowerBound());
    chartPlot.setUpperBound(range.getUpperBound());

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    Color color = jrPlot.getMercuryColor();
    if (color != null) {
        chartPlot.setMercuryPaint(color);
        chartPlot.setUseSubrangePaint(false);
    }

    // localizing the default format, can be overridden by display.getMask()
    chartPlot.setValueFormat(NumberFormat.getNumberInstance(getLocale()));

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }

        if (display.getMask() != null) {
            chartPlot.setValueFormat(
                    new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale())));
        }

        if (display.getFont() != null) {
            chartPlot.setValueFont(fontUtil.getAwtFont(display.getFont(), getLocale()));
        }
    }

    // Set the location of where the value is displayed
    switch (jrPlot.getValueLocationValue()) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null,
            chartPlot, isShowLegend());

    // Set the generic options
    configureChart(jfreeChart);

    return jfreeChart;
}

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

@Override
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());

    ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
    // setting localized range axis formatters
    chartPlot.getRangeAxis().setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));

    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null,
            chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend());

    // Set the generic options
    configureChart(jfreeChart, getPlot());
    jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    jfreeChart.setBorderVisible(false);//from   w  w  w.j av a  2s.com

    Range range = convertRange(jrPlot.getDataRange());

    if (range != null) {
        // Set the boundary of the thermomoter
        chartPlot.setLowerBound(range.getLowerBound());
        chartPlot.setUpperBound(range.getUpperBound());
    }
    chartPlot.setGap(0);

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    Paint paint = jrPlot.getMercuryColor();
    if (paint != null) {
        chartPlot.setUseSubrangePaint(false);
    } else {
        //it has no effect, but is kept for backward compatibility reasons
        paint = ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(0);
    }

    chartPlot.setMercuryPaint(paint);

    chartPlot.setThermometerPaint(THERMOMETER_COLOR);
    chartPlot.setThermometerStroke(new BasicStroke(2f));
    chartPlot.setOutlineVisible(false);
    chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD));

    // localizing the default format, can be overridden by display.getMask()
    chartPlot.setValueFormat(NumberFormat.getNumberInstance(getLocale()));

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }
        if (display.getMask() != null) {
            chartPlot.setValueFormat(
                    new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale())));
        }
        if (display.getFont() != null) {
            //            chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD));
        }
    }

    // Set the location of where the value is displayed
    ValueLocationEnum valueLocation = jrPlot.getValueLocationValue();
    switch (valueLocation) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    return jfreeChart;

}

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

/**
 * Build and run a thermometer chart.  JFreeChart thermometer charts have some
 * limitations.  They always have a maximum of three ranges, and the colors of those
 * ranges seems to be fixed./*w w  w.j ava2 s. co  m*/
 */
protected JFreeChart createThermometerChart() throws JRException {
    JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot();

    // Create the plot that will hold the thermometer.
    ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset());

    ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
    // setting localized range axis formatters
    chartPlot.getRangeAxis().setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));

    Range range = convertRange(jrPlot.getDataRange());

    // Set the boundary of the thermomoter
    chartPlot.setLowerBound(range.getLowerBound());
    chartPlot.setUpperBound(range.getUpperBound());

    // Units can only be Fahrenheit, Celsius or none, so turn off for now.
    chartPlot.setUnits(ThermometerPlot.UNITS_NONE);

    // Set the color of the mercury.  Only used when the value is outside of
    // any defined ranges.
    Color color = jrPlot.getMercuryColor();
    if (color != null) {
        chartPlot.setMercuryPaint(color);
        chartPlot.setUseSubrangePaint(false);
    }

    // localizing the default format, can be overridden by display.getMask()
    chartPlot.setValueFormat(NumberFormat.getNumberInstance(getLocale()));

    // Set the formatting of the value display
    JRValueDisplay display = jrPlot.getValueDisplay();
    if (display != null) {
        if (display.getColor() != null) {
            chartPlot.setValuePaint(display.getColor());
        }
        if (display.getMask() != null) {
            chartPlot.setValueFormat(
                    new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale())));
        }
        if (display.getFont() != null) {
            //            chartPlot.setValueFont(getFontUtil().getAwtFont(display.getFont()));
        }
    }

    // Set the location of where the value is displayed
    ValueLocationEnum valueLocation = jrPlot.getValueLocationValue();
    switch (valueLocation) {
    case NONE:
        chartPlot.setValueLocation(ThermometerPlot.NONE);
        break;
    case LEFT:
        chartPlot.setValueLocation(ThermometerPlot.LEFT);
        break;
    case RIGHT:
        chartPlot.setValueLocation(ThermometerPlot.RIGHT);
        break;
    case BULB:
    default:
        chartPlot.setValueLocation(ThermometerPlot.BULB);
        break;
    }

    // Define the three ranges
    range = convertRange(jrPlot.getLowRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getMediumRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound());
    }

    range = convertRange(jrPlot.getHighRange());
    if (range != null) {
        chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound());
    }

    // Build a chart around this plot
    JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null,
            chartPlot, isShowLegend());

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

    return jfreeChart;
}