List of usage examples for org.jfree.chart.plot.dial DialValueIndicator setPaint
public void setPaint(Paint paint)
From source file:com.bdb.weather.display.current.Hygrometer.java
private ChartViewer createChartElements() { humidityPlot.addLayer(/* www . ja v a2 s .co m*/ new DialBackground(new GradientPaint(0.0f, 0.0f, Color.LIGHT_GRAY, 100.0f, 0.0f, Color.blue))); StandardDialScale scale = new StandardDialScale(Humidity.MIN_HUMIDITY.get(), Humidity.MAX_HUMIDITY.get(), 240.0, -300.0, 10.0, 9); scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN)); scale.setTickRadius(.9); scale.setTickLabelFormatter(new DecimalFormat("#")); scale.setTickLabelOffset(.2); scale.setTickLabelPaint(Color.BLACK); humidityPlot.addScale(0, scale); humidityPlot.setDialFrame(new StandardDialFrame()); DialValueIndicator valueInd = new DialValueIndicator(0); valueInd.setNumberFormat(new DecimalFormat("# '%rH'")); Color c = new Color(255, 255, 255, 0); valueInd.setBackgroundPaint(c); valueInd.setOutlinePaint(c); valueInd.setPaint(Color.cyan); humidityPlot.addLayer(valueInd); double angle = valueInd.getAngle(); double radius = valueInd.getRadius(); trendAnnotation.setPaint(Color.cyan); trendAnnotation.setAngle(angle); trendAnnotation.setRadius(radius + .1); humidityPlot.addLayer(trendAnnotation); DialPointer.Pointer pointer = new DialPointer.Pointer(0); humidityPlot.addPointer(pointer); DialCap cap = new DialCap(); cap.setRadius(cap.getRadius() * 1.5); humidityPlot.setCap(cap); range = new StandardDialRange(Humidity.MIN_HUMIDITY.get(), Humidity.MAX_HUMIDITY.get(), Color.BLACK); range.setInnerRadius(.40); range.setOuterRadius(.45); range.setScaleIndex(0); humidityPlot.addLayer(range); JFreeChart chart = new JFreeChart(humidityPlot); chart.setBackgroundPaint(Color.GRAY); ChartViewer chartViewer = new ChartViewer(chart); //chartViewer.setMinHeight(100); //chartViewer.setMinWidth(100); //chartViewer.setMaxHeight(400); //chartViewer.setMaxWidth(400); //chartViewer.setBackground(Color.GRAY); return chartViewer; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SBISpeedometer.java
/** * Creates a chart of type speedometer./*from w w w. j a va2s. c o m*/ * * @param chartTitle the chart title. * @param dataset the dataset. * * @return A chart speedometer. */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); Dataset dataset = (Dataset) datasets.getDatasets().get("1"); DialPlot plot = new DialPlot(); plot.setDataset((ValueDataset) dataset); plot.setDialFrame(new StandardDialFrame()); plot.setBackground(new DialBackground()); if (dialtextuse) { DialTextAnnotation annotation1 = new DialTextAnnotation(dialtext); annotation1.setFont(styleTitle.getFont()); annotation1.setRadius(0.7); plot.addLayer(annotation1); } DialValueIndicator dvi = new DialValueIndicator(0); dvi.setFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize())); dvi.setPaint(labelsValueStyle.getColor()); plot.addLayer(dvi); StandardDialScale scale = new StandardDialScale(lower, upper, -120, -300, 10.0, 4); if (!(increment > 0)) { logger.warn("increment cannot be less than 0, put default to 0.1"); increment = 0.01; } scale.setMajorTickIncrement(increment); // if (!( minorTickCount > 0)){ // logger.warn("minor tick count cannot be less than 0, put default to 1"); // minorTickCount = 1; // } scale.setMinorTickCount(minorTickCount); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); //set tick label style Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize()); scale.setTickLabelFont(tickLabelsFont); scale.setTickLabelPaint(labelsTickStyle.getColor()); plot.addScale(0, scale); plot.addPointer(new DialPointer.Pin()); DialCap cap = new DialCap(); plot.setCap(cap); // sets intervals for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), interval.getColor()); range.setInnerRadius(0.52); range.setOuterRadius(0.55); plot.addLayer(range); } GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(db); plot.removePointer(0); DialPointer.Pointer p = new DialPointer.Pointer(); p.setFillPaint(Color.yellow); plot.addPointer(p); logger.debug("OUT"); JFreeChart chart = new JFreeChart(name, plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.setBackgroundPaint(color); return chart; }
From source file:com.bdb.weather.display.current.Barometer.java
private ChartViewer createChartElements(Pressure min, Pressure max) { Color backgroundDialColor = StageUtilities .toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_DIAL_COLOR)); Paint backgroundPaint = new GradientPaint(0.0f, 0.0f, Color.LIGHT_GRAY, 100.0f, 0.0f, backgroundDialColor); DialBackground background = new DialBackground(backgroundPaint); plot.addLayer(background);/*from w w w . j a v a2 s . co m*/ double dialTickIncrements = .2; switch (Pressure.getDefaultUnit()) { case IN_HG: dialTickIncrements = .2; break; case HECTO_PASCAL: case MILLIBAR: dialTickIncrements = 10.0; break; } scale = new StandardDialScale(min.get(), max.get(), 240.0, -300.0, dialTickIncrements, 10); scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN)); scale.setTickRadius(.9); scale.setTickLabelFormatter(Pressure.getDefaultFormatter()); scale.setTickLabelOffset(.25); scale.setTickLabelPaint( StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_SCALE_TEXT))); scale.setMajorTickPaint( StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_SCALE_TICK))); scale.setMinorTickPaint( StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_SCALE_TICK))); plot.addScale(0, scale); plot.setDialFrame(new StandardDialFrame()); DialValueIndicator valueInd = new DialValueIndicator(0); // // Set background and outline paint to be completely transparent so they do not show at all // valueInd.setBackgroundPaint(new Color(255, 255, 255, 0)); valueInd.setOutlinePaint(new Color(255, 255, 255, 0)); valueInd.setPaint(StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_VALUE))); valueInd.setNumberFormat(Pressure.getDefaultUnit().getFormatterWithUnit()); plot.addLayer(valueInd); double angle = valueInd.getAngle(); double radius = valueInd.getRadius(); trendAnnotation.setPaint(StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_VALUE))); trendAnnotation.setAngle(angle); trendAnnotation.setRadius(radius + .1); plot.addLayer(trendAnnotation); DialPointer.Pointer pointer = new DialPointer.Pointer(0); plot.addPointer(pointer); DialCap cap = new DialCap(); cap.setRadius(cap.getRadius() * 1.5); plot.setCap(cap); range = new StandardDialRange(0.0, 360.0, StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_VALUE_RANGE))); range.setInnerRadius(.40); range.setOuterRadius(.45); range.setScaleIndex(0); plot.addLayer(range); JFreeChart chart = new JFreeChart(plot); chart.setBackgroundPaint( StageUtilities.toAwtColor(colorPrefs.getColorPref(ColorPreferences.GUAGE_BACKGROUND))); ChartViewer chartViewer = new ChartViewer(chart); chartViewer.setMinHeight(200); chartViewer.setMinWidth(200); chartViewer.setMaxHeight(10000); chartViewer.setMaxWidth(10000); //chartViewer.setBorder(new BevelBorder(BevelBorder.RAISED)); return chartViewer; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SimpleDial.java
/** * Creates the chart .//from w w w. j a v a 2 s . c om * * @param chartTitle the chart title. * @param dataset the dataset. * * @return A chart . */ public JFreeChart createChart(DatasetMap datasets) { // get data for diagrams logger.debug("IN"); Dataset dataset = (Dataset) datasets.getDatasets().get("1"); DialPlot plot = new DialPlot(); plot.setDataset((ValueDataset) dataset); ArcDialFrame dialFrame = null; if (!horizontalView) { plot.setView(0.78, 0.37, 0.22, 0.26); dialFrame = new ArcDialFrame(-10.0, 20.0); } else { plot.setView(0.21, 0.0, 0.58, 0.30); dialFrame = new ArcDialFrame(60.0, 60.0); } dialFrame.setInnerRadius(0.65); dialFrame.setOuterRadius(0.90); dialFrame.setForegroundPaint(Color.darkGray); dialFrame.setStroke(new BasicStroke(3.0f)); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(240, 240, 240)); DialBackground sdb = new DialBackground(gp); GradientPaintTransformType gradientPaintTransformType = GradientPaintTransformType.VERTICAL; if (horizontalView) { gradientPaintTransformType = GradientPaintTransformType.HORIZONTAL; } sdb.setGradientPaintTransformer(new StandardGradientPaintTransformer(gradientPaintTransformType)); plot.addLayer(sdb); if (!(increment > 0)) { logger.warn("increment cannot be less than 0, put default to 0.1 "); increment = 0.1; } StandardDialScale scale = null; if (!horizontalView) { scale = new StandardDialScale(lower, upper, -8, 16.0, increment, minorTickCount); } else { scale = new StandardDialScale(lower, upper, 115.0, -50.0, increment, minorTickCount); } // sets intervals for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), interval.getColor()); range.setInnerRadius(0.70); range.setOuterRadius(0.75); plot.addLayer(range); } scale.setTickRadius(0.88); scale.setTickLabelOffset(0.07); //set tick label style Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize()); scale.setTickLabelFont(tickLabelsFont); scale.setTickLabelPaint(labelsTickStyle.getColor()); //scale.setMajorTickIncrement(25.0); plot.addScale(0, scale); DialPointer needle = new DialPointer.Pin(); needle.setRadius(0.82); plot.addLayer(needle); DialValueIndicator dvi = new DialValueIndicator(0); dvi.setFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize())); dvi.setPaint(labelsValueStyle.getColor()); plot.addLayer(dvi); JFreeChart chart1 = new JFreeChart(plot); chart1.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart1.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart1.addSubtitle(subTitle); } logger.debug("OUT"); return chart1; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
protected JFreeChart makeDialChart(ChartModel chartModel, BasicDataModel data) { DialPlot chartBeansDialPlot = (DialPlot) chartModel.getPlot(); org.jfree.chart.plot.dial.DialPlot jFreeDialPlot = new SquareDialPlot(); final DefaultValueDataset dataset = new DefaultValueDataset(); dataset.setValue(scaleNumber(data.getData().get(0), data.getScalingFactor())); jFreeDialPlot.setDataset(dataset);/* w ww.j a v a2s .co m*/ final DoubleLineDialFrame dialFrame = new DoubleLineDialFrame(); dialFrame.setForegroundPaint(new Color(0x8d8d8d)); dialFrame.setInnerForegroundPaint(new Color(0x5d5d5d)); dialFrame.setStroke(new BasicStroke(2)); dialFrame.setBackgroundPaint(Color.WHITE); jFreeDialPlot.setDialFrame(dialFrame); for (DialRange dialRange : chartBeansDialPlot.getScale()) { if (dialRange.getColor() != null) { SingleLineDialRange standarddialrange = new SingleLineDialRange( dialRange.getMinValue().doubleValue(), dialRange.getMaxValue().doubleValue(), new Color(0x00FFFFFF & dialRange.getColor())); standarddialrange.setInnerRadius(0.4D); jFreeDialPlot.addLayer(standarddialrange); } } double scaleMajorTickIncrement = (chartBeansDialPlot.getScale().getMaxValue().doubleValue() - chartBeansDialPlot.getScale().getMinValue().doubleValue()) / 5; FixedStandardDialScale standardDialScale = new FixedStandardDialScale( chartBeansDialPlot.getScale().getMinValue().doubleValue(), chartBeansDialPlot.getScale().getMaxValue().doubleValue(), -150.0, -240.0, scaleMajorTickIncrement, 2); standardDialScale.setTickRadius(0.88D); standardDialScale.setTickLabelOffset(0.15D); standardDialScale .setTickLabelFont(ChartUtils.getFont("sans-serif", FontStyle.NORMAL, FontWeight.NORMAL, 10)); standardDialScale.setTickLabelPaint(Color.BLACK); standardDialScale.setMajorTickLength(0.04); standardDialScale.setMajorTickPaint(Color.BLACK); standardDialScale.setMajorTickStroke(new BasicStroke(2)); standardDialScale.setMinorTickLength(0.02); standardDialScale.setMinorTickPaint(new Color(0x8b8b8b)); standardDialScale.setMinorTickStroke(new BasicStroke(1)); jFreeDialPlot.addScale(0, standardDialScale); DialCap dialCap = new DialCap(); dialCap.setRadius(0.06); dialCap.setFillPaint(new Color(0x636363)); dialCap.setOutlinePaint(new Color(0x5d5d5d)); dialCap.setOutlineStroke(new BasicStroke(2)); jFreeDialPlot.setCap(dialCap); GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(0xfcfcfc), new Point(), new Color(0xd7d8da)); DialBackground dialbackground = new DialBackground(gradientpaint); // specify Color here for no gradient dialbackground.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); jFreeDialPlot.setBackground(dialbackground); VariableStrokePointer pointer = new VariableStrokePointer(); pointer.setRadius(0.9); pointer.setOutlineStroke(new BasicStroke(2)); pointer.setWidthRadius(0.05); pointer.setFillPaint(new Color(0x636363)); pointer.setOutlinePaint(new Color(0x5d5d5d)); jFreeDialPlot.addPointer(pointer); DialValueIndicator dialValueIndicator = new DialValueIndicator(0); dialValueIndicator.setTemplateValue(chartBeansDialPlot.getScale().getMaxValue()); dialValueIndicator.setFont(ChartUtils.getFont("Dialog", FontStyle.NORMAL, FontWeight.BOLD, 10)); dialValueIndicator.setPaint(Color.BLACK); dialValueIndicator.setBackgroundPaint(Color.WHITE); dialValueIndicator.setOutlineStroke(new BasicStroke(1)); dialValueIndicator.setOutlinePaint(new Color(0x8b8b8b)); jFreeDialPlot.addLayer(dialValueIndicator); if ((chartBeansDialPlot.getAnnotation() != null) && (chartBeansDialPlot.getAnnotation().getText() != null) && (chartBeansDialPlot.getAnnotation().getText().trim().length() > 0)) { Font font = ChartUtils.getFont(chartBeansDialPlot.getAnnotation().getFontFamily(), chartBeansDialPlot.getAnnotation().getFontStyle(), chartBeansDialPlot.getAnnotation().getFontWeight(), chartBeansDialPlot.getAnnotation().getFontSize()); if (font == null) { font = ChartUtils.getFont("sans-serif", FontStyle.NORMAL, FontWeight.NORMAL, 10); } DialTextAnnotation dialTextAnnotation = new DialTextAnnotation( chartBeansDialPlot.getAnnotation().getText().trim()); dialTextAnnotation.setFont(font); dialTextAnnotation.setRadius(0.6); jFreeDialPlot.addLayer(dialTextAnnotation); } String title = ""; if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null) && (chartModel.getTitle().getText().trim().length() > 0)) { title = chartModel.getTitle().getText(); } JFreeChart chart = new JFreeChart(title, jFreeDialPlot); initChart(chart, chartModel); return chart; }
From source file:org.pentaho.chart.plugin.jfreechart.chart.dial.JFreeDialChartGenerator.java
public void setDialValueIndicator(ChartDocument chartDocument, DialPlot dialPlot) { // ~ params begin Font valueIndicatorFont = new Font("Dialog", Font.BOLD, 14); //$NON-NLS-1$ Color valueIndicatorPaint = Color.black; Color valueIndicatorBackgroundPaint = Color.white; Stroke valueIndicatorOutlineStroke = new BasicStroke(1.0f); Color valueIndicatorOutlinePaint = Color.blue; // ~ params end ChartElement valIndicatorElement = getUniqueElement(chartDocument, DIALVALUEINDICATOR); Color valIndicatorColorTmp = ColorFactory.getInstance().getColor(valIndicatorElement); if (valIndicatorColorTmp != null) { valueIndicatorPaint = valIndicatorColorTmp; }//w w w.j a v a2s .com Color valIndicatorBgColorTmp = ColorFactory.getInstance().getColor(valIndicatorElement, BorderStyleKeys.BACKGROUND_COLOR); if (valIndicatorBgColorTmp != null) { valueIndicatorBackgroundPaint = valIndicatorBgColorTmp; } final BasicStroke borderStyleStroke = StrokeFactory.getInstance().getBorderStroke(valIndicatorElement); if (borderStyleStroke != null) { valueIndicatorOutlineStroke = borderStyleStroke; } Color valIndicatorBorderColorTmp = ColorFactory.getInstance().getColor(valIndicatorElement, BorderStyleKeys.BORDER_TOP_COLOR); if (valIndicatorBorderColorTmp != null) { valueIndicatorOutlinePaint = valIndicatorBorderColorTmp; } Font valIndicatorFontTmp = JFreeChartUtils.getFont(valIndicatorElement); if (valIndicatorFontTmp != null) { valueIndicatorFont = valIndicatorFontTmp; } DialValueIndicator dialValueIndicator = new DialValueIndicator(0); // begin code to determine the size of the value indicator box ChartElement scaleElement = getUniqueElement(chartDocument, SCALE); if (scaleElement != null) { double scaleUpperBound = Double.parseDouble(scaleElement.getAttribute(UPPERBOUND).toString()); double scaleLowerBound = Double.parseDouble(scaleElement.getAttribute(LOWERBOUND).toString()); if (Math.abs(scaleUpperBound) > Math.abs(scaleLowerBound)) { dialValueIndicator.setTemplateValue(scaleUpperBound); } else { dialValueIndicator.setTemplateValue(scaleLowerBound); } } // end code to determine the size of the value indicator box dialValueIndicator.setFont(valueIndicatorFont); dialValueIndicator.setPaint(valueIndicatorPaint); dialValueIndicator.setBackgroundPaint(valueIndicatorBackgroundPaint); dialValueIndicator.setOutlineStroke(valueIndicatorOutlineStroke); dialValueIndicator.setOutlinePaint(valueIndicatorOutlinePaint); dialPlot.addLayer(dialValueIndicator); }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *//*from w w w . j ava2 s. c o m*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7; StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / (tickCount - 1), 15); scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); if (jrPlot.getTickLabelFont() != null) { scale.setTickLabelFont(fontUtil.getAwtFont(jrPlot.getTickLabelFont(), getLocale())); } scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); // localizing the default tick label formatter scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); dialPlot.addScale(0, scale); List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 0) { colorStep = 255 / size; } for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); dialRange.setInnerRadius(0.41); dialRange.setOuterRadius(0.41); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.valueOf(displayVisibility)) { DialValueIndicator dvi = new DialValueIndicator(0); // we need the transparent paint because null is not accepted dvi.setBackgroundPaint(TRANSPARENT_PAINT); // dvi.setFont(fontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) { dvi.setNumberFormat(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); } dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(PROPERTY_DIAL_LABEL) : null; if (label != null) { JRFont displayFont = display == null ? null : display.getFont(); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); if (displayFont != null) { dialAnnotation.setFont(fontUtil.getAwtFont(displayFont, getLocale())); } if (display != null && display.getColor() != null) { dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); } dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); needle.setVisible(true); needle.setRadius(0.91); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.DARK_GRAY); cap.setOutlinePaint(Color.GRAY); cap.setOutlineStroke(new BasicStroke(0.5f)); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, dialPlot, isShowLegend()); // Set all the generic options configureChart(jfreeChart); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * *//*from w ww. j a v a 2 s . c om*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / 6, 15); scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 0) colorStep = 255 / size; for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); dialRange.setInnerRadius(0.41); dialRange.setOuterRadius(0.41); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.parseBoolean(displayVisibility)) { DialValueIndicator dvi = new DialValueIndicator(0); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern)); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); needle.setVisible(true); needle.setRadius(0.91); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.DARK_GRAY); cap.setOutlinePaint(Color.GRAY); cap.setOutlineStroke(new BasicStroke(0.5f)); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, dialPlot, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * *//*from w w w . j a va2 s .c o m*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / 6, 15); scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRBaseFont font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getTickLabelFont(), font); JRFontUtil.copyNonNullOwnProperties(jrPlot.getTickLabelFont(), font); font = new JRBaseFont(getChart(), font); scale.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale())); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 0) colorStep = 255 / size; for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); dialRange.setInnerRadius(0.41); dialRange.setOuterRadius(0.41); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.parseBoolean(displayVisibility)) { DialValueIndicator dvi = new DialValueIndicator(0); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern)); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { JRFont displayFont = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getDisplayFont(), displayFont); JRFontUtil.copyNonNullOwnProperties(jrPlot.getValueDisplay().getFont(), displayFont); displayFont = new JRBaseFont(getChart(), displayFont); Font themeDisplayFont = JRFontUtil.getAwtFont(displayFont, getLocale()); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); needle.setVisible(true); needle.setRadius(0.91); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.DARK_GRAY); cap.setOutlinePaint(Color.GRAY); cap.setOutlineStroke(new BasicStroke(0.5f)); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, dialPlot, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * *///from w w w . j ava 2 s .co m protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7; StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / (tickCount - 1), 15); scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); // localizing the default tick label formatter scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); dialPlot.addScale(0, scale); List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 0) colorStep = 255 / size; for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); dialRange.setInnerRadius(0.41); dialRange.setOuterRadius(0.41); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.parseBoolean(displayVisibility)) { DialValueIndicator dvi = new DialValueIndicator(0); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(getFontUtil().getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); needle.setVisible(true); needle.setRadius(0.91); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.DARK_GRAY); cap.setOutlinePaint(Color.GRAY); cap.setOutlineStroke(new BasicStroke(0.5f)); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, dialPlot, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }