List of usage examples for org.jfree.chart.plot ThermometerPlot setUnits
public void setUnits(String u)
From source file:org.cyberoam.iview.charts.Thermometer.java
/** * This method generates JFreeChart instance for Thermometer chart with iView customization. * @param reportID// w w w . j a v a2 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 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.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);// w w w. ja v a2 s.c o 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:org.sonar.plugins.ral.GaugeChart.java
@Override protected Plot getPlot(ChartParameters params) { ThermometerPlot plot = new ThermometerPlot(createDataset(params)); plot.setGap(1);/*from w ww . j av a 2s. c o 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:AppPackage.humidity.java
public humidity() { try {//ww w . j a v a 2 s .c o m JFrame window = new JFrame(); window.setSize(1000, 615); window.setBackground(Color.blue.darker()); double value = 45; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - window.getWidth()) / 2); int y = (int) ((dimension.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); DefaultValueDataset dataset = new DefaultValueDataset(value); ThermometerPlot thermometerplot = new ThermometerPlot(dataset); thermometerplot.setSubrangePaint(0, Color.green.darker()); thermometerplot.setSubrangePaint(1, Color.orange); thermometerplot.setSubrangePaint(2, Color.red); JFreeChart jfreechart = new JFreeChart("Humidity readings", JFreeChart.DEFAULT_TITLE_FONT, thermometerplot, true); thermometerplot.setInsets(new RectangleInsets(5D, 5D, 5D, 5D)); thermometerplot.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); thermometerplot.setThermometerStroke(new BasicStroke(2.0F)); thermometerplot.setThermometerPaint(Color.BLUE); thermometerplot.setUnits(0); thermometerplot.setGap(3); window.add(new ChartPanel(jfreechart), BorderLayout.CENTER); window.setVisible(true); } catch (Exception e) { System.out.print("Chart exception:" + e); } initComponents(); }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.Thermometer.java
/** * Creates a chart of type thermometer.// w ww.j a v a2 s.c om * * @return A chart thermometer. */ public JFreeChart createChart() { logger.debug("IN"); if (dataset == null) { logger.debug("The dataset to be represented is null"); return null; } ThermometerPlot plot = new ThermometerPlot((ValueDataset) dataset); logger.debug("Created the new Thermometer Plot"); JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, true); logger.debug("Created the new Chart"); chart.setBackgroundPaint(color); logger.debug("Setted the background color of the chart"); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); logger.debug("Setted the title of the chart"); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); logger.debug("Setted the subtitle of the chart"); } 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.setRange(lower, upper); plot.setUnits(ThermometerPlot.UNITS_NONE); logger.debug("Setted all the properties of the plot"); // set subranges for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval subrange = (KpiInterval) iterator.next(); int range = 0; //For the thermometer the number of intervals is forced to 3 and they have to have as labels the following ones 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()); } logger.debug("Setted new range of the plot"); } logger.debug("OUT"); return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.Thermometer.java
/** * Creates a chart of type thermometer./*from w w w .ja v a2s. c o m*/ * * @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:biz.ixnay.pivot.charts.skin.jfree.ThermometerViewSkin.java
@Override protected JFreeChart createChart() { ValueDataset value = getDataset();/*w w w . java 2s . c om*/ ThermometerPlot plot = new ThermometerPlot(value); // TODO: set style values before creating the chart object SingleValueChartView chartView = (SingleValueChartView) getComponent(); SingleValueChartView.ValueRange bounds = chartView.getValueBounds(); plot.setRange(bounds.getLower(), bounds.getUpper()); for (SingleValueChartView.Range range : SingleValueChartView.Range.values()) { SingleValueChartView.ValueRange rangeBounds = chartView.getValueRange(range); if (rangeBounds != null) { double lower = rangeBounds.getLower(); double upper = rangeBounds.getUpper(); switch (range) { case NORMAL: plot.setSubrange(ThermometerPlot.NORMAL, lower, upper); break; case WARNING: plot.setSubrange(ThermometerPlot.WARNING, lower, upper); break; case CRITICAL: plot.setSubrange(ThermometerPlot.CRITICAL, lower, upper); break; } } } if (units != null) { switch (units) { case NONE: plot.setUnits(ThermometerPlot.UNITS_NONE); break; case CELSIUS: plot.setUnits(ThermometerPlot.UNITS_CELCIUS); break; case FAHRENHEIT: plot.setUnits(ThermometerPlot.UNITS_FAHRENHEIT); break; case KELVIN: plot.setUnits(ThermometerPlot.UNITS_KELVIN); break; } } if (bulbRadius > 0) { plot.setBulbRadius(bulbRadius); } return createChart(plot); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample thermometer chart. * * @return a sample thermometer chart./*from www .j a v a 2s . c om*/ */ public JFreeChart createThermometerChart() { // create a default chart based on some sample data... final String title = this.resources.getString("meter.thermo.title"); final String subtitleStr = this.resources.getString("meter.thermo.subtitle"); final String units = this.resources.getString("meter.thermo.units"); final DefaultValueDataset data = new DefaultValueDataset(new Double(34.0)); final ThermometerPlot plot = new ThermometerPlot(data); plot.setUnits(units); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java
/** * *//* w w w.j a v a2s. 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()); // 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 va 2 s . 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()); // 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; }