List of usage examples for org.jfree.chart.plot.dial DialPlot addLayer
public void addLayer(DialLayer layer)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SimpleDial.java
/** * Creates the chart ./*w w w . j a va 2 s .co m*/ * * @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.chart.dial.JFreeDialChartGenerator.java
protected void setDialRange(ChartDocument chartDocument, DialPlot dialPlot) { final double rangeInnerRadius = 0.4D; ChartElement[] rangeElements = getElements(chartDocument, DIALRANGE); for (int i = 0; i < rangeElements.length; i++) { double lowerBound = Double.parseDouble(rangeElements[i].getAttribute(LOWERBOUND).toString()); double upperBound = Double.parseDouble(rangeElements[i].getAttribute(UPPERBOUND).toString()); final Color rangeColorTmp = ColorFactory.getInstance().getColor(rangeElements[i]); Color rangeColor = Color.BLACK; if (rangeColorTmp != null) { rangeColor = rangeColorTmp;// w ww . j av a2s . c om } SingleLineDialRange standarddialrange = new SingleLineDialRange(lowerBound, upperBound, rangeColor); standarddialrange.setInnerRadius(rangeInnerRadius); dialPlot.addLayer(standarddialrange); } }
From source file:org.pentaho.chart.plugin.jfreechart.chart.dial.JFreeDialChartGenerator.java
protected void setDialTextAnnotation(ChartDocument chartDocument, DialPlot dialPlot) { // ~ params begin Font textAnnotationFont = new Font("Dialog", Font.BOLD, 14); //$NON-NLS-1$ Color textAnnotationPaint = Color.black; final double textAnnotationRadius = 0.69999999999999996D; // hard-coded for now // ~ params end ChartElement annotationElement = getUniqueElement(chartDocument, ANNOTATION); if (annotationElement != null && annotationElement.getText() != null) { String annotation = annotationElement.getText(); Color annotationColorTmp = ColorFactory.getInstance().getColor(annotationElement); if (annotationColorTmp != null) { textAnnotationPaint = annotationColorTmp; }/* w w w . j a v a2s. c o m*/ Font annotationFontTmp = JFreeChartUtils.getFont(annotationElement); if (annotationFontTmp != null) { textAnnotationFont = annotationFontTmp; } DialTextAnnotation dialtextannotation = new DialTextAnnotation(annotation); dialtextannotation.setFont(textAnnotationFont); dialtextannotation.setPaint(textAnnotationPaint); dialtextannotation.setRadius(textAnnotationRadius); dialPlot.addLayer(dialtextannotation); } }
From source file:se.technipelago.weather.chart.Generator.java
private void createWindDial(float speed, float high, final String filename) throws IOException { ValueDataset dataset1 = new DefaultValueDataset(speed); ValueDataset dataset2 = new DefaultValueDataset(high); // get data for diagrams DialPlot plot = new DialPlot(); plot.setView(0.0, 0.0, 1.0, 1.0);/* ww w . j a v a 2 s. c om*/ plot.setDataset(0, dataset1); plot.setDataset(1, dataset2); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.darkGray); plot.setDialFrame(dialFrame); 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); // Wind Speed DialTextAnnotation annotation1 = new DialTextAnnotation("m/s"); annotation1.setFont(new Font("Dialog", Font.BOLD, 10)); annotation1.setRadius(0.76); plot.addLayer(annotation1); DialValueIndicator dvi = new DialValueIndicator(0); dvi.setFont(new Font("Dialog", Font.PLAIN, 9)); dvi.setOutlinePaint(Color.darkGray); //dvi.setBackgroundPaint(new Color(0xee, 0xee, 0xf6)); NumberFormat fmt = new DecimalFormat("#"); fmt.setMaximumFractionDigits(1); fmt.setMinimumIntegerDigits(1); dvi.setNumberFormat(fmt); dvi.setRadius(0.71); dvi.setAngle(-89.0); // -103 dvi.setInsets(new RectangleInsets(0.0, 2.0, 0.0, 2.0)); // top, left, bottom, right plot.addLayer(dvi); StandardDialScale scale = new StandardDialScale(0, 20, -120, -300, 1, 0); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10)); NumberFormat fmt3 = new DecimalFormat("#"); fmt3.setMaximumFractionDigits(0); scale.setTickLabelFormatter(fmt3); plot.addScale(0, scale); // Add needles. // To make the average speed needle the front-most needle, // it must be added after high speed needle. // High speed needle. DialPointer needle2 = new DialPointer.Pin(1); needle2.setRadius(0.62); plot.addLayer(needle2); // Average speed needle. DialPointer needle = new DialPointer.Pointer(0); Color darkGreen = new Color(0x15, 0x49, 0x1f); ((DialPointer.Pointer) needle).setFillPaint(darkGreen); plot.addLayer(needle); // Add a cap at the dial center. DialCap cap = new DialCap(); cap.setRadius(0.10); plot.setCap(cap); JFreeChart chart = new JFreeChart(plot); //TextTitle title = new TextTitle("Vindhastighet", new Font("Dialog", Font.BOLD, 12)); //title.setPaint(Color.DARK_GRAY); //chart.setTitle(title); chart.setBackgroundPaint(VERY_LIGHT_GRAY); OutputStream out = null; try { out = new FileOutputStream(outputDir != null ? outputDir + "/" + filename : filename); ChartUtilities.writeChartAsPNG(out, chart, DIAL_WIDTH, DIAL_HEIGHT); } finally { if (out != null) { out.close(); } } }
From source file:se.technipelago.weather.chart.Generator.java
private void createTemperatureDial(float temperature, int humidity, final String filename) throws IOException { ValueDataset dataset1 = new DefaultValueDataset(temperature); ValueDataset dataset2 = new DefaultValueDataset(humidity); // get data for diagrams DialPlot plot = new DialPlot(); plot.setView(0.0, 0.0, 1.0, 1.0);/*from w ww . j a va 2 s . co m*/ plot.setDataset(0, dataset1); plot.setDataset(1, dataset2); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.darkGray); plot.setDialFrame(dialFrame); 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); // Temperature DialTextAnnotation annotation1 = new DialTextAnnotation("\u00B0C"); annotation1.setFont(new Font("Dialog", Font.BOLD, 10)); annotation1.setRadius(0.76); plot.addLayer(annotation1); // Humidity DialTextAnnotation annotation2 = new DialTextAnnotation("%"); annotation2.setFont(new Font("Dialog", Font.BOLD, 10)); annotation2.setPaint(Color.blue); annotation2.setRadius(0.4); plot.addLayer(annotation2); // Temperature DialValueIndicator dvi = new DialValueIndicator(0); dvi.setFont(new Font("Dialog", Font.PLAIN, 9)); dvi.setOutlinePaint(Color.darkGray); //dvi.setBackgroundPaint(new Color(0xee, 0xee, 0xf6)); NumberFormat fmt = new DecimalFormat("#"); fmt.setMaximumFractionDigits(1); fmt.setMinimumIntegerDigits(1); dvi.setNumberFormat(fmt); dvi.setRadius(0.71); dvi.setAngle(-88.0); // -103 dvi.setInsets(new RectangleInsets(0.0, 8.0, 0.0, 2.0)); // top, left, bottom, right plot.addLayer(dvi); StandardDialScale scale = new StandardDialScale(-30, 30, -120, -300, 5, 4); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10)); NumberFormat fmt3 = new DecimalFormat("#"); fmt3.setMaximumFractionDigits(0); scale.setTickLabelFormatter(fmt3); plot.addScale(0, scale); // Humidity DialValueIndicator dvi2 = new DialValueIndicator(1); dvi2.setFont(new Font("Dialog", Font.PLAIN, 9)); dvi2.setOutlinePaint(Color.blue); //dvi2.setBackgroundPaint(new Color(0xee, 0xee, 0xf6)); NumberFormat fmt2 = new DecimalFormat("#"); fmt2.setMaximumFractionDigits(0); dvi2.setNumberFormat(fmt2); dvi2.setRadius(0.59); dvi2.setAngle(-90.0); // -77 dvi2.setInsets(new RectangleInsets(0.0, 1.0, 0.0, 1.0)); plot.addLayer(dvi2); StandardDialScale scale2 = new StandardDialScale(0, 100, -120, -300, 10, 4); scale2.setTickRadius(0.50); scale2.setTickLabelOffset(0.15); scale2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 9)); scale2.setTickLabelFormatter(fmt3); scale2.setMajorTickPaint(Color.blue); plot.addScale(1, scale2); plot.mapDatasetToScale(1, 1); // Add needles. // To make the temperature needle the front-most needle, // it must be added after humidity needle. // Humidity needle. DialPointer needle2 = new DialPointer.Pin(1); needle2.setRadius(0.50); plot.addLayer(needle2); // Temperature needle. DialPointer needle = new DialPointer.Pointer(0); Color darkGreen = new Color(0x15, 0x49, 0x1f); ((DialPointer.Pointer) needle).setFillPaint(darkGreen); plot.addLayer(needle); // Add a cap at the dial center. DialCap cap = new DialCap(); cap.setRadius(0.10); plot.setCap(cap); JFreeChart chart = new JFreeChart(plot); //TextTitle title = new TextTitle("Temperatur/luftfuktighet", new Font("Dialog", Font.BOLD, 12)); //title.setPaint(Color.DARK_GRAY); //chart.setTitle(title); chart.setBackgroundPaint(VERY_LIGHT_GRAY); OutputStream out = null; try { out = new FileOutputStream(outputDir != null ? outputDir + "/" + filename : filename); ChartUtilities.writeChartAsPNG(out, chart, DIAL_WIDTH, DIAL_HEIGHT); } finally { if (out != null) { out.close(); } } }
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; }/*from ww w. j a v a2s . c o m*/ 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
/** * */// w w w.ja v a 2 s.com 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.AegeanChartTheme.java
/** * */// www .j a v a 2 s . c o m protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); } StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setForegroundPaint(Color.BLACK); dialFrame.setBackgroundPaint(Color.BLACK); dialFrame.setStroke(new BasicStroke(1f)); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setBackground(db); ScaledDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); scale = new ScaledDialScale(lowerBound, upperBound, 210, -240, (upperBound - lowerBound) / 6, 1); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0")); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.0")); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.00")); } } else { scale = new ScaledDialScale(); } 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.7f)); scale.setMajorTickPaint(Color.BLACK); scale.setMinorTickPaint(Color.BLACK); 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 > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 15f); dialRange.setInnerRadius(0.5); dialRange.setOuterRadius(0.5); 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.valueOf(displayVisibility).booleanValue()) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); 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) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); 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(Color.BLACK); dialAnnotation.setRadius(Math.sin(Math.PI / 6.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new ScaledDialPointer(dialUnitScale, 0.047); needle.setVisible(true); needle.setRadius(0.7); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.BLACK); cap.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * */// ww w . jav a2 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())); 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.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * *//*from www .jav a2 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); 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; }