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

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

Introduction

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

Prototype

public void setMercuryPaint(Paint paint) 

Source Link

Document

Sets the default mercury paint and sends a PlotChangeEvent to all registered listeners.

Usage

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

/**
 * This method generates JFreeChart instance for Thermometer chart with iView customization. 
 * @param reportID/*from w w w  .  j  a v a 2 s. co 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 dataset = 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));
        rsw.next();
        double free = Double.parseDouble(rsw.getString(yColumnDBname));
        dataset = new DefaultValueDataset((100 * used) / (used + free));
        ThermometerPlot plot = new ThermometerPlot(dataset);
        chart = new JFreeChart("", // chart title
                JFreeChart.DEFAULT_TITLE_FONT, plot, // plot
                false); // include legend
        chart.setBackgroundPaint(Color.white);
        plot.setThermometerStroke(new BasicStroke(2.0f));
        plot.setThermometerPaint(Color.DARK_GRAY);
        plot.setBulbRadius(30);
        plot.setColumnRadius(15);
        plot.setUnits(ThermometerPlot.UNITS_NONE);
        plot.setMercuryPaint(Color.WHITE);
        plot.setValueFont(new Font("Vandara", Font.CENTER_BASELINE, 12));
        plot.setBackgroundPaint(Color.white);
        plot.setBackgroundAlpha(0.0f);
        plot.setOutlineVisible(false);
        plot.setSubrangeInfo(0, 0, 50);
        plot.setSubrangeInfo(1, 50, 85);
        plot.setSubrangeInfo(2, 85, 100);
        plot.setSubrangePaint(0, new Color(75, 200, 85));
        plot.setSubrangePaint(1, new Color(254, 211, 41));
        plot.setSubrangePaint(2, new Color(255, 85, 85));

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

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   ww w. ja v a 2 s  . com*/

    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:Componentes.TermometroMax.java

@Override
public void pintar(javax.swing.JPanel p, int pos) {
    p.removeAll();/*from w w  w  . j av a2  s  . c  om*/
    DefaultValueDataset data = new DefaultValueDataset(new Double(ventana.getGraphdata().getTmax()));

    ThermometerPlot plot = new ThermometerPlot(data);
    chart = new JFreeChart("Temperatura Maxima, \nMES: " + Calculos.get_mes(ventana.getMonthdata().getdata()), // chart title
            JFreeChart.DEFAULT_TITLE_FONT, plot, // plot
            false);

    Color Darkorange = new Color(255, 140, 0);
    Color Crimson = new Color(220, 20, 60);
    Color Aquamarine = new Color(127, 255, 212);
    Color Darkslategray = new Color(47, 79, 79);

    plot.setMercuryPaint(Aquamarine);
    plot.setSubrange(NORMAL, 0, 10);
    plot.setSubrange(WARNING, 10.1, 20);
    plot.setSubrange(CRITICAL, 20.1, 50);
    plot.setSubrangePaint(NORMAL, Aquamarine);
    plot.setSubrangePaint(WARNING, Darkorange);
    plot.setSubrangePaint(CRITICAL, Crimson);

    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Darkslategray);

    plot.setDisplayRange(5, Calculos.get_min(datos.getTmax()), Calculos.get_max(datos.getTmax()));
    plot.setRange(Calculos.get_min(datos.getTmax()), Calculos.get_max(datos.getTmax()));

    panel = new ChartPanel(chart);
    panel.setBounds(5, 5, 300, 300);
    panel.repaint();
    p.add(panel);
    // jPanel1.repaint();
    p.updateUI();
    // aoIndex=aoAux;
    ///aoAux = 0;
}

From source file:Componentes.TermometroMin.java

@Override
public void pintar(javax.swing.JPanel p, int pos) {
    p.removeAll();/* www . j a v  a  2  s .c o  m*/
    DefaultValueDataset data = new DefaultValueDataset(new Double(ventana.getGraphdata().getTmin()));

    ThermometerPlot plot = new ThermometerPlot(data);
    chart = new JFreeChart("Temperatura Mnima, \nMES: " + Calculos.get_mes(ventana.getMonthdata().getdata()), // chart title
            JFreeChart.DEFAULT_TITLE_FONT, plot, // plot
            false);
    Color Darkorange = new Color(255, 140, 0);
    Color Crimson = new Color(220, 20, 60);
    Color Aquamarine = new Color(127, 255, 212);
    Color Darkslategray = new Color(47, 79, 79);

    plot.setMercuryPaint(Aquamarine);
    plot.setSubrange(NORMAL, 0, 2.5);
    plot.setSubrange(WARNING, 2.6, 7.5);
    plot.setSubrange(CRITICAL, 7.6, 20);
    plot.setSubrangePaint(NORMAL, Aquamarine);
    plot.setSubrangePaint(WARNING, Darkorange);
    plot.setSubrangePaint(CRITICAL, Crimson);

    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Darkslategray);

    plot.setDisplayRange(2, Calculos.get_min(datos.getTmin()), Calculos.get_max(datos.getTmin()));
    plot.setRange(Calculos.get_min(datos.getTmin()), Calculos.get_max(datos.getTmin()));

    panel = new ChartPanel(chart);
    panel.setBounds(5, 5, 300, 300);
    panel.repaint();
    p.add(panel);
    // jPanel1.repaint();
    p.updateUI();
    // aoIndex=aoAux;
    ///aoAux = 0;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.ThermometerChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final Plot plot = chart.getPlot();
    final ThermometerPlot thermometerPlot = (ThermometerPlot) plot;

    if (isShowBorder() == false || isChartSectionOutline() == false) {
        chart.setBorderVisible(false);/* www . j  a  v a 2 s  .co  m*/
        thermometerPlot.setOutlineVisible(false);
    }

    if (getThermometerUnits() != null) {
        thermometerPlot.setUnits(getThermometerUnits().getUnitConstant());
    }
    thermometerPlot.setLowerBound(
            Math.min(getCriticalRangeLow(), Math.min(getNormalRangeLow(), getWarningRangeLow())));
    thermometerPlot.setUpperBound(
            Math.max(getCriticalRangeHigh(), Math.max(getNormalRangeHigh(), getWarningRangeHigh())));
    thermometerPlot.setBulbRadius(getBulbRadius());
    thermometerPlot.setColumnRadius(getColumnRadius());
    thermometerPlot.setSubrange(ThermometerPlot.CRITICAL, getCriticalRangeLow(), getCriticalRangeHigh());
    thermometerPlot.setSubrange(ThermometerPlot.WARNING, getWarningRangeLow(), getWarningRangeHigh());
    thermometerPlot.setSubrange(ThermometerPlot.NORMAL, getNormalRangeLow(), getNormalRangeHigh());
    if (getMercuryPaint() != null) {
        thermometerPlot.setMercuryPaint(getMercuryPaint());
    }
    if (getThermometerPaint() != null) {
        thermometerPlot.setThermometerPaint(getThermometerPaint());
    }

    if (getCriticalRangeColor() != null) {
        thermometerPlot.setSubrangePaint(ThermometerPlot.CRITICAL, getCriticalRangeColor());
    }
    if (getWarningRangeColor() != null) {
        thermometerPlot.setSubrangePaint(ThermometerPlot.WARNING, getWarningRangeColor());
    }
    if (getNormalRangeColor() != null) {
        thermometerPlot.setSubrangePaint(ThermometerPlot.NORMAL, getNormalRangeColor());
    }
}

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

/**
 *
 *//*from w w  w  . j  ava 2s. com*/
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

/**
 *
 */// www  .  j a v a  2  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());
    // 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);//ww w . ja v a2  s .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.
    @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.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);/*w  w  w .  ja v a  2s  .  c  o  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.
    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.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  av  a  2  s. com*/
 */
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;
}