List of usage examples for org.jfree.chart.plot MeterPlot setUnits
public void setUnits(String units)
From source file:org.jfree.chart.demo.MeterChartDemo.java
/** * Displays a meter chart./* w w w . ja va 2 s.co m*/ * * @param value the value. * @param shape the dial shape. */ void displayMeterChart(final double value, final DialShape shape) { final DefaultValueDataset data = new DefaultValueDataset(75.0); final MeterPlot plot = new MeterPlot(data); plot.setUnits("Degrees"); plot.setRange(new Range(20.0, 140.0)); // plot.setNormalRange(new Range(70.0, 100.0)); // plot.setWarningRange(new Range(100.0, 120.0)); // plot.setCriticalRange(new Range(120.0, 140.0)); plot.setDialShape(shape); plot.setNeedlePaint(Color.white); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 9)); // plot.setInsets(new Insets(5, 5, 5, 5)); final JFreeChart chart = new JFreeChart("Meter Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); // final MeterLegend legend = new MeterLegend("Sample Meter"); // chart.setLegend(legend); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final JFrame chartFrame = new ChartFrame("Meter Chart", chart); chartFrame.addWindowListener(new WindowAdapter() { /** * Invoked when a window is in the process of being closed. * The close operation can be overridden at this point. */ public void windowClosing(final WindowEvent e) { System.exit(0); } }); chartFrame.pack(); RefineryUtilities.positionFrameRandomly(chartFrame); chartFrame.setSize(250, 250); chartFrame.setVisible(true); }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
/** * Creates a JFreeChart object from a dial definition object. All of the settings for the dial image are defined * by the dial definition./* ww w. j ava 2s . c om*/ * * @param widget * The dial definition object. * @param title * The dial title. * @param units * The dial units * @return A JFreeChart object for the dial */ private static JFreeChart createDial(final DialWidgetDefinition widget, final String title, final String units) { MeterPlot meter = new MeterPlot(widget); JFreeChartEngine.updatePlot(meter, widget); meter.setUnits(units); meter.setValuePaint(widget.getValuePaint()); meter.setTickPaint(widget.getTickPaint()); int tickSize = widget.getTickSize(); if (tickSize == 0) { meter.setTickLabelsVisible(false); } else { meter.setTickLabelsVisible(true); meter.setTickSize(tickSize); } if (widget.getValueFont() != null) { meter.setValueFont(widget.getValueFont()); } else { meter.setValuePaint(JFreeChartEngine.getTransparent()); } // TODO support title fonts in the definition Font titleFont = widget.getTitleFont(); JFreeChart chart = new JFreeChart(title, titleFont, meter, false); // TODO support any other MeterPlot properties return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.Meter.java
/** * Creates the chart ./*from ww w.j av a2 s . c o m*/ * * @param chartTitle the chart title. * @param dataset the dataset. * * @return A chart . */ public JFreeChart createChart(DatasetMap datasets) { Dataset dataset = (Dataset) datasets.getDatasets().get("1"); MeterPlot plot = new MeterPlot((ValueDataset) dataset); plot.setRange(new Range(lower, upper)); for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()), Color.lightGray, new BasicStroke(2.0f), interval.getColor())); } plot.setNeedlePaint(Color.darkGray); plot.setDialBackgroundPaint(Color.white); plot.setDialOutlinePaint(Color.gray); plot.setDialShape(DialShape.CHORD); plot.setMeterAngle(260); plot.setTickLabelsVisible(true); //set tick label style Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize()); plot.setTickLabelFont(tickLabelsFont); plot.setTickLabelPaint(labelsTickStyle.getColor()); plot.setTickSize(5.0); plot.setTickPaint(Color.lightGray); if (units != null) { plot.setUnits(units); } plot.setValuePaint(labelsValueStyle.getColor()); plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize())); JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } return chart; }
From source file:org.adempiere.webui.apps.graph.WPerformanceIndicator.java
private JFreeChart createChart() { JFreeChart chart = null;//from www . jav a2s .c o m // Set Text StringBuffer text = new StringBuffer(m_goal.getName()); if (m_goal.isTarget()) text.append(": ").append(m_goal.getPercent()).append("%"); else text.append(": ").append(s_format.format(m_goal.getMeasureActual())); m_text = text.toString(); // ToolTip text = new StringBuffer(); if (m_goal.getDescription() != null) text.append(m_goal.getDescription()).append(": "); text.append(s_format.format(m_goal.getMeasureActual())); if (m_goal.isTarget()) text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ") .append(s_format.format(m_goal.getMeasureTarget())); setTooltiptext(text.toString()); // DefaultValueDataset data = new DefaultValueDataset((float) m_goal.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = m_goal.getColorSchema(); int rangeLo = 0; int rangeHi = 0; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range colorSchema.getColor(rangeHi), new BasicStroke(7.0f), new Color(-13091716))); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(new Color(-13091716)); plot.setUnits(""); plot.setDialShape(DialShape.CHORD);//CIRCLE); plot.setNeedlePaint(Color.white); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setValueFont(new Font("SansSerif", Font.BOLD, 8)); plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelPaint(Color.white); plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 9), plot, false); return chart; }
From source file:com.liferay.server.admin.web.internal.portlet.action.ViewChartMVCResourceCommand.java
protected MeterPlot getMeterPlot(ThemeDisplay themeDisplay, ValueDataset valueDataset) { MeterPlot meterPlot = new MeterPlot(valueDataset); meterPlot.addInterval(new MeterInterval(themeDisplay.translate("normal"), new Range(0.0D, 75D), Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64))); meterPlot.addInterval(new MeterInterval(themeDisplay.translate("warning"), new Range(75D, 90D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64))); meterPlot.addInterval(new MeterInterval(themeDisplay.translate("critical"), new Range(90D, 100D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128))); meterPlot.setDialBackgroundPaint(Color.white); meterPlot.setDialShape(DialShape.PIE); meterPlot.setDialOutlinePaint(Color.gray); meterPlot.setTickLabelFont(new Font(null, Font.PLAIN, 10)); meterPlot.setTickLabelPaint(Color.darkGray); meterPlot.setTickLabelsVisible(true); meterPlot.setTickPaint(Color.lightGray); meterPlot.setTickSize(5D);/* w w w .j ava2 s .c om*/ meterPlot.setMeterAngle(180); meterPlot.setNeedlePaint(Color.darkGray); meterPlot.setRange(new Range(0.0D, 100D)); meterPlot.setValueFont(new Font(null, Font.PLAIN, 10)); meterPlot.setValuePaint(Color.black); meterPlot.setUnits("%"); return meterPlot; }
From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java
private void renderMeterChart(JFreeChart chart, LoadType loadType, ComputeBean hpc) { MeterPlot plot = (MeterPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.addInterval(/* w ww. jav a 2 s . c o m*/ new MeterInterval("High", new Range(85.0, 100.0), Color.RED, new BasicStroke(), Color.RED)); plot.addInterval(new MeterInterval("Low", new Range(0.0, 85.0))); plot.setDialOutlinePaint(Color.blue); plot.setNeedlePaint(Color.WHITE); plot.setDialBackgroundPaint(Color.BLACK); plot.setTickPaint(Color.WHITE); plot.setTickLabelsVisible(true); plot.setTickLabelPaint(Color.WHITE); if (loadType.equals(LoadType.DISK)) { plot.setUnits("% peak (" + hpc.getLoad().getDisk() + "GB/" + hpc.getTotalDisk() + "GB)"); } else if (loadType.equals(LoadType.CPU)) { plot.setUnits("% peak (" + hpc.getLoad().getCpu() + "/" + hpc.getTotalCpu() + ")"); } else if (loadType.equals(LoadType.QUEUE)) { plot.setUnits("% peak (" + hpc.getLoad().getJobsRunning() + "R/" + (hpc.getLoad().getJobsOther() + hpc.getLoad().getJobsQueued()) + ")O"); } else { plot.setUnits("% Relative to Max"); } }
From source file:org.adempiere.apps.graph.PerformanceIndicator.java
private JFreeChart createChart() { JFreeChart chart = null;// w w w .jav a2 s . co m // Set Text StringBuffer text = new StringBuffer(m_goal.getName()); if (m_goal.isTarget()) text.append(": ").append(m_goal.getPercent()).append("%"); else text.append(": ").append(s_format.format(m_goal.getMeasureActual())); m_text = text.toString(); // ToolTip text = new StringBuffer(); if (m_goal.getDescription() != null) text.append(m_goal.getDescription()).append(": "); text.append(s_format.format(m_goal.getMeasureActual())); if (m_goal.isTarget()) text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ") .append(s_format.format(m_goal.getMeasureTarget())); setToolTipText(text.toString()); // //setBackground(m_goal.getColor()); setForeground(GraphUtil.getForeground(getBackground())); // Performance Line int percent = m_goal.getPercent(); if (percent > 100) // draw 100% line m_line = s_width100; else // draw Performance Line m_line = s_width100 * m_goal.getGoalPerformanceDouble(); String title = m_text; DefaultValueDataset data = new DefaultValueDataset((float) m_goal.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = m_goal.getColorSchema(); int rangeLo = 0; int rangeHi = 0; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range colorSchema.getColor(rangeHi), new BasicStroke(7.0f), //Color.lightGray new Color(-13091716) //Color.gray )); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(new Color(-13091716));//Color.GRAY); plot.setUnits(m_goal.getName()); plot.setDialShape(DialShape.CHORD);//CIRCLE); //plot.setDialBackgroundPaint(new GradientPaint(0, 0, m_goal.getColor(), 0, 1000, Color.black)); plot.setNeedlePaint(Color.white); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); plot.setTickLabelPaint(Color.white); plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0)); chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 15), plot, false); return chart; }
From source file:org.adempiere.webui.apps.graph.jfreegraph.PerformanceGraphBuilder.java
public JFreeChart createIndicatorChart(IndicatorModel model) { JFreeChart chart = null;/* ww w. jav a 2 s . c o m*/ DefaultValueDataset data = new DefaultValueDataset((float) model.goalModel.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = model.goalModel.getColorSchema(); int rangeLo = 0; int rangeHi = 0; Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(50, 50); float[] dist = { 0.0f, 0.2f, 0.45f, 0.75f, 1.0f }; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { Color[] colors = { colorSchema.getColor(rangeHi).brighter().brighter(), colorSchema.getColor(rangeHi).brighter(), colorSchema.getColor(rangeHi), colorSchema.getColor(rangeHi).darker(), colorSchema.getColor(rangeHi).darker().darker() }; LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors); plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range p, new BasicStroke(7.0f), model.dialBackground)); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(model.dialBackground); plot.setUnits(""); plot.setDialShape(DialShape.CHORD); plot.setNeedlePaint(model.needleColor); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setValueFont(new Font("SansSerif", Font.BOLD, 8)); plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelPaint(model.tickColor); plot.setValuePaint(new Color(0.0f, 0.0f, 0.0f, 0.0f)); plot.setTickPaint(model.tickColor); // chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 9), plot, false); return chart; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *//*ww w . j ava 2 s.co m*/ protected JFreeChart createMeterChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // Start by creating the plot that will hold the meter MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset()); // Set the shape MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.PIE : jrPlot.getShapeValue(); switch (shape) { case CHORD: chartPlot.setDialShape(DialShape.CHORD); break; case CIRCLE: chartPlot.setDialShape(DialShape.CIRCLE); break; case PIE: default: chartPlot.setDialShape(DialShape.PIE); } // Set the meter's range chartPlot.setRange(convertRange(jrPlot.getDataRange())); // Set the size of the meter int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger(); chartPlot.setMeterAngle(meterAngle); // Set the units - this is just a string that will be shown next to the // value String units = jrPlot.getUnits(); if (units != null && units.length() > 0) { chartPlot.setUnits(units); } // Set the font used for tick labels if (jrPlot.getTickLabelFont() != null) { chartPlot.setTickLabelFont(fontUtil.getAwtFont(jrPlot.getTickLabelFont(), getLocale())); } // Set the spacing between ticks. I hate the name "tickSize" since to me it // implies I am changing the size of the tick, not the spacing between them. double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble(); chartPlot.setTickSize(tickInterval); // Set all the colors we support Color color = jrPlot.getMeterBackgroundColor(); if (color != null) { chartPlot.setDialBackgroundPaint(color); } color = jrPlot.getNeedleColor(); if (color != null) { chartPlot.setNeedlePaint(color); } // localizing the default format, can be overridden by display.getMask() chartPlot.setTickLabelFormat(NumberFormat.getInstance(getLocale())); // Set how the value is displayed. JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { if (display.getColor() != null) { chartPlot.setValuePaint(display.getColor()); } if (display.getMask() != null) { chartPlot.setTickLabelFormat( new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale()))); } if (display.getFont() != null) { chartPlot.setValueFont(fontUtil.getAwtFont(display.getFont(), getLocale())); } } color = jrPlot.getTickColor(); if (color != null) { chartPlot.setTickPaint(color); } // Now define all of the intervals, setting their range and color List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null) { Iterator<JRMeterInterval> iter = intervals.iterator(); while (iter.hasNext()) { JRMeterInterval interval = iter.next(); chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, isShowLegend()); // Set all the generic options configureChart(jfreeChart); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * Build and configure a meter chart.// w ww . j a va 2 s. c o m * * @param evaluation current expression evaluation phase * @throws JRException */ protected JFreeChart createMeterChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // Start by creating the plot that will hold the meter MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset()); // Set the shape MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.PIE : jrPlot.getShapeValue(); if (shape == MeterShapeEnum.CHORD) chartPlot.setDialShape(DialShape.CHORD); else if (shape == MeterShapeEnum.CIRCLE) chartPlot.setDialShape(DialShape.CIRCLE); else if (shape == MeterShapeEnum.DIAL) return createDialChart(); else chartPlot.setDialShape(DialShape.PIE); // Set the meter's range chartPlot.setRange(convertRange(jrPlot.getDataRange())); // Set the size of the meter int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger().intValue(); chartPlot.setMeterAngle(meterAngle); // Set the units - this is just a string that will be shown next to the // value String units = jrPlot.getUnits(); if (units != null && units.length() > 0) chartPlot.setUnits(units); // Set the spacing between ticks. I hate the name "tickSize" since to me it // implies I am changing the size of the tick, not the spacing between them. double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble().doubleValue(); chartPlot.setTickSize(tickInterval); // Set all the colors we support Color color = jrPlot.getMeterBackgroundColor(); if (color != null) chartPlot.setDialBackgroundPaint(color); color = jrPlot.getNeedleColor(); if (color != null) chartPlot.setNeedlePaint(color); JRBaseFont font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getTickLabelFont(), font); JRFontUtil.copyNonNullOwnProperties(jrPlot.getTickLabelFont(), font); font = new JRBaseFont(getChart(), font); chartPlot.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale())); // Set how the value is displayed. JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { if (display.getColor() != null) { chartPlot.setValuePaint(display.getColor()); } if (display.getMask() != null) { chartPlot.setTickLabelFormat(new DecimalFormat(display.getMask())); } font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getDisplayFont(), font); JRFontUtil.copyNonNullOwnProperties(jrPlot.getValueDisplay().getFont(), font); font = new JRBaseFont(getChart(), font); chartPlot.setValueFont(JRFontUtil.getAwtFont(font, getLocale())); } color = jrPlot.getTickColor(); if (color != null) chartPlot.setTickPaint(color); // Now define all of the intervals, setting their range and color List intervals = jrPlot.getIntervals(); if (intervals != null) { Iterator iter = intervals.iterator(); while (iter.hasNext()) { JRMeterInterval interval = (JRMeterInterval) iter.next(); if (interval != null) chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, chartPlot, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }