List of usage examples for org.jfree.chart JFreeChart setTitle
public void setTitle(String text)
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.SimpleDial.java
/** * Creates the chart .//w w w .j a va 2 s. co m * * @return A Simple Dial chart . */ public JFreeChart createChart() { logger.debug("IN"); if (dataset == null) { logger.debug("The dataset to be represented is null"); return null; } DialPlot plot = new DialPlot(); plot.setDataset((ValueDataset) dataset); logger.debug("Created the new Dial Plot"); ArcDialFrame dialFrame = null; 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.HORIZONTAL; sdb.setGradientPaintTransformer(new StandardGradientPaintTransformer(gradientPaintTransformType)); plot.addLayer(sdb); increment = (upper - lower) / 4; StandardDialScale scale = null; 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); Font f = new Font("Arial", Font.PLAIN, 11); scale.setTickLabelFont(f); //scale.setMajorTickIncrement(25.0); plot.addScale(0, scale); DialPointer needle = new DialPointer.Pin(); needle.setRadius(0.82); plot.addLayer(needle); JFreeChart chart1 = new JFreeChart(plot); logger.debug("Created the chart"); chart1.setBackgroundPaint(color); logger.debug("Setted background color of the chart"); TextTitle title = setStyleTitle(name, styleTitle); chart1.setTitle(title); logger.debug("Setted the title of the chart"); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart1.addSubtitle(subTitle); logger.debug("Setted the subtitle of the chart"); } logger.debug("OUT"); return chart1; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.linecharts.LineChart.java
public JFreeChart createChart() { logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); NumberAxis rangeAxis = new NumberAxis("Kpi Values"); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); Color colorLabel = Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis);// w ww .jav a 2s . co m CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator = null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12)); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index = -1; index = datasetLine.getRowIndex(serName); Color color = Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0, datasetLine); plot.setRenderer(0, lineRenderer); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
From source file:net.praqma.jenkins.memorymap.MemoryMapBuildAction.java
protected JFreeChart createPairedBarCharts(String title, String yaxis, double max, double min, CategoryDataset dataset, List<ValueMarker> markers) { final CategoryAxis domainAxis = new ShiftedCategoryAxis(null); final NumberAxis rangeAxis = new NumberAxis(yaxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(max);//from www .j a va 2 s . c om rangeAxis.setLowerBound(min); /*TODO : wrong scale choosen - Jes * if the user selects Mega or Giga as the scale, but there only are * a couple of Kilo in the graph it would have no ticks on the axis. * this can be solved by. redefining the ticks, * We have not done this because it's a bit tricky to figure out the rigth * factor to devid with * * but the method wuld be * double factor = 10 * rangeAxis.setStandardTickUnits(new StandardTickUnitSource(max / factor)); */ //StackedAreaRenderer2 renderer = new StackedAreaRenderer2(); BarRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); for (ValueMarker mkr : markers) { plot.addRangeMarker(mkr); } JFreeChart chart = new JFreeChart(plot); chart.setPadding(new RectangleInsets(30, 15, 15, 15)); chart.setTitle(title); return chart; }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java
public JFreeChart createChart() { logger.debug("IN"); CategoryPlot plot = new CategoryPlot(); IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder(); String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName"); NumberAxis rangeAxis = new NumberAxis(rangeAxisName); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12)); Color colorLabel = Color.decode("#000000"); rangeAxis.setLabelPaint(colorLabel); rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); rangeAxis.setTickLabelPaint(colorLabel); plot.setRangeAxis(rangeAxis);/*from w w w .ja va 2s. c o m*/ CategoryAxis domainAxis = new CategoryAxis(); domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setLabelPaint(colorLabel); domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); domainAxis.setTickLabelPaint(colorLabel); plot.setDomainAxis(domainAxis); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); //I create a line renderer MyStandardCategoryItemLabelGenerator generator = null; LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(); lineRenderer.setShapesFilled(true); lineRenderer.setBaseItemLabelGenerator(generator); lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12)); lineRenderer.setBaseItemLabelPaint(colorLabel); lineRenderer.setBaseItemLabelsVisible(true); DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line"); for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) { String serName = (String) iterator.next(); String labelName = ""; int index = -1; index = datasetLine.getRowIndex(serName); Color color = Color.decode("#990200"); lineRenderer.setSeriesPaint(index, color); } plot.setDataset(0, datasetLine); plot.setRenderer(0, lineRenderer); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); JFreeChart chart = new JFreeChart(plot); logger.debug("Chart created"); TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.setTitle(title); TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle); TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS); chart.addSubtitle(subTitle2); chart.removeLegend(); chart.setBackgroundPaint(Color.white); logger.debug("OUT"); return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java
/** * Creates a chart for the specified dataset. * /*ww w. j a v a 2s. c o m*/ * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); //Creates the xAxis with its label and style NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setLabel(xLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } //Creates the yAxis with its label and style NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(false); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setTickLabelsVisible(true); yAxis.setLabel(yLabel); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); Color outboundCol = new Color(Integer.decode(outboundColor).intValue()); //Sets the graph paint scale and the legend paintscale LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(), outboundCol); LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol); for (int ke = 0; ke <= (zvalues.length - 1); ke++) { Double key = (new Double(zvalues[ke])); Color temp = (Color) colorRangeMap.get(key); paintScale.add(zvalues[ke], temp); legendPaintScale.add(0.5 + ke, temp); } //Configures the renderer XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setPaintScale(paintScale); double blockHeight = (new Double(blockH)).doubleValue(); double blockWidth = (new Double(blockW)).doubleValue(); renderer.setBlockWidth(blockWidth); renderer.setBlockHeight(blockHeight); //configures the plot with title, subtitle, axis ecc. XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); plot.setDomainCrosshairPaint(Color.black); plot.setForegroundAlpha(0.66f); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); //Sets legend labels SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels); scaleAxis.setRange(0.5, 0.5 + zvalues.length); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); scaleAxis.setLabel(zLabel); //scaleAxis.setLabelAngle(3.14/2); scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); //draws legend as chart subtitle PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis); psl.setAxisOffset(2.0); psl.setPosition(RectangleEdge.RIGHT); psl.setMargin(new RectangleInsets(5, 1, 5, 1)); chart.addSubtitle(psl); if (yLabels != null) { //Sets y legend labels LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white); for (int ke = 0; ke < yLabels.length; ke++) { Color temp = Color.white; legendPaintScale2.add(1 + ke, temp); } SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels); scaleAxis2.setRange(0, (yLabels.length - 1)); scaleAxis2.setPlot(new PiePlot()); scaleAxis2.setGridBandsVisible(false); //draws legend as chart subtitle PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2); psl2.setAxisOffset(5.0); psl2.setPosition(RectangleEdge.LEFT); psl2.setMargin(new RectangleInsets(8, 1, 40, 1)); psl2.setStripWidth(0); psl2.setStripOutlineVisible(false); chart.addSubtitle(psl2); } return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.clusterchart.SimpleCluster.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createBubbleChart(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, legend, true, false);/*from www . j a va2 s.c o m*/ /*Font font = new Font("Tahoma", Font.BOLD, titleDimension); TextTitle title = new TextTitle(name, font); chart.setTitle(title);*/ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } Color colorSubInvisibleTitle = Color.decode("#FFFFFF"); StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle); TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle); chart.addSubtitle(subsubTitle); chart.setBackgroundPaint(color); XYPlot plot = (XYPlot) chart.getPlot(); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); //plot.setForegroundAlpha(0.50f); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //define colors int seriesN = dataset.getSeriesCount(); if (colorMap != null) { boolean isSerieSel = true; for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); String tmpName = serieName.replaceAll(" ", ""); tmpName = tmpName.replace('.', ' ').trim(); if (serie_selected != null && serie_selected.size() > 0) { String serieSel = serie_selected.get(tmpName).toString(); isSerieSel = (serieSel.equalsIgnoreCase("TRUE") || serieSel.equalsIgnoreCase("YES") || serieSel.equalsIgnoreCase("1")) ? true : false; serieName = tmpName; } if (color != null && isSerieSel) { Color color = (Color) colorMap.get(serieName); renderer.setSeriesPaint(i, color); } else { Color color = new Color(Integer.decode(defaultColor).intValue()); renderer.setSeriesPaint(i, color); } } } // increase the margins to account for the fact that the auto-range // doesn't take into account the bubble size... NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setLabelPaint(styleXaxesLabels.getColor()); rangeAxis .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize())); rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor()); //rangeAxis.setAutoRange(true); rangeAxis.setRange(xMin, xMax); TickUnits units = null; if (decimalXValues == false) units = (TickUnits) NumberAxis.createIntegerTickUnits(); else units = (TickUnits) NumberAxis.createStandardTickUnits(); rangeAxis.setStandardTickUnits(units); TickUnits domainUnits = null; if (decimalYValues == false) domainUnits = (TickUnits) NumberAxis.createIntegerTickUnits(); else domainUnits = (TickUnits) NumberAxis.createStandardTickUnits(); domainAxis.setStandardTickUnits(domainUnits); rangeAxis.setLowerMargin(1.0); rangeAxis.setUpperMargin(1.0); domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setLabelPaint(styleYaxesLabels.getColor()); domainAxis .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize())); domainAxis.setTickLabelPaint(styleYaxesLabels.getColor()); domainAxis.setLowerMargin(1.0); domainAxis.setUpperMargin(1.0); //DecimalFormat format=(new DecimalFormat("0")); //rangeAxis.setNumberFormatOverride(format); if (legend == true) drawLegend(chart); return chart; }
From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java
private static void applyProperties(JFreeChart chart, Map<String, Object> properties) { if (properties != null) { String text = (String) properties.get(TITLE); if (text != null) { TextTitle title = chart.getTitle(); if (title == null) { title = new TextTitle(); chart.setTitle(title); }/*from w w w.j a va 2 s. c o m*/ title.setText(text); Font titleFont = (Font) properties.get(TITLEFONT); if (titleFont != null) title.setFont(titleFont); Paint paint = (Paint) properties.get(TITLECOLOR); if (paint != null) title.setPaint(paint); } else chart.setTitle((TextTitle) null); Plot plot = chart.getPlot(); Paint paint = (Paint) properties.get(BGCOLOR); if (paint != null) plot.setBackgroundPaint(paint); paint = (Color) properties.get(OUTLINEPAINT); if (paint != null) plot.setOutlinePaint(paint); Stroke stroke = (Stroke) properties.get(OUTLINESTROKE); if (stroke != null) plot.setOutlineStroke(stroke); PlotOrientation orientation = (PlotOrientation) properties.get(ORIENTATION); Axis domainAxis = null; Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); if (orientation != null) p.setOrientation(orientation); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); if (orientation != null) p.setOrientation(orientation); } if (domainAxis != null) applyAxisProperties(domainAxis, "x", properties); //$NON-NLS-1$ if (rangeAxis != null) applyAxisProperties(rangeAxis, "y", properties); //$NON-NLS-1$ Boolean anti = (Boolean) properties.get(ANTIALIAS); if (anti != null) chart.setAntiAlias(anti); paint = (Paint) properties.get(CANVASPAINT); if (paint != null) chart.setBackgroundPaint(paint); } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.WinLose.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createBarChart(name, null, null, dataset, PlotOrientation.VERTICAL, legend, false, false);/*from w w w . j av a2 s.co m*/ chart.setBorderVisible(false); chart.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(color); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); plot.setRangeCrosshairPaint(color.BLACK); // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setCategoryMargin(0.2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); rangeAxis.setRange(new Range(-(barHeight + 0.2), (barHeight + 0.2))); // customize renderer MyBarRendererThresholdPaint renderer = new MyBarRendererThresholdPaint(useTargets, thresholds, dataset, timeSeries, nullValues, bottomThreshold, color); if (wlt_mode.doubleValue() == 0) { renderer.setBaseItemLabelsVisible(Boolean.FALSE, true); } else { renderer.setBaseItemLabelsVisible(Boolean.TRUE, true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.#")) { public String generateLabel(CategoryDataset dataset, int row, int column) { if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0) return ""; String columnKey = (String) dataset.getColumnKey(column); int separator = columnKey.indexOf('-'); String month = columnKey.substring(0, separator); String year = columnKey.substring(separator + 1); int monthNum = Integer.parseInt(month); if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) { if (wlt_mode.doubleValue() == 2 && column % 2 == 0) return ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, monthNum - 1); SimpleDateFormat dataFormat = new SimpleDateFormat("MMM"); return dataFormat.format(calendar.getTime()); } else return "" + monthNum; } }); } if (wlt_mode.doubleValue() == 3) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2)); } else if (wlt_mode.doubleValue() == 4 || wlt_mode.doubleValue() == 5) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4)); } if (legend == true) { LegendItemCollection collection = createThresholdLegend(plot); plot.setFixedLegendItems(collection); } if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth); } //renderer.setSeriesPaint(0, Color.BLUE); plot.setRenderer(renderer); logger.debug("OUT"); if (mainThreshold == null) return null; return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SimpleDial.java
/** * Creates the chart ./*from w w w . j a v a2s. 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.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java
@Override public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) { GraphBuilder builder = new GraphBuilder(); builder.setMGoal(goalModel.goal);/* w w w .j av a 2 s . com*/ builder.setXAxisLabel(goalModel.xAxisLabel); builder.setYAxisLabel(goalModel.yAxisLabel); builder.loadDataSet(goalModel.columnList); JFreeChart chart = builder.createChart(goalModel.chartType); ChartRenderingInfo info = new ChartRenderingInfo(); chart.getPlot().setForegroundAlpha(0.6f); if (goalModel.zoomFactor > 0) { chartWidth = chartWidth * goalModel.zoomFactor / 100; chartHeight = chartHeight * goalModel.zoomFactor / 100; } if (!goalModel.showTitle) { chart.setTitle(""); } BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, info); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); myImage.setContent(image); parent.appendChild(myImage); int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { continue; } Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG_" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener<Event>() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { List<GraphColumn> list = goalModel.columnList; for (int i = 0; i < list.size(); i++) { String s = "_WG_" + list.get(i).getLabel(); if (areaId.endsWith(s)) { chartMouseClicked(goalModel.goal, list.get(i)); return; } } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); return false; } return true; }