List of usage examples for org.jfree.chart.block ColumnArrangement ColumnArrangement
public ColumnArrangement()
From source file:gda.plots.SimpleLegendTitle.java
/** * Exactly the same as the SuperClass constructor - necessary because there is no default constructor in * LegendTitle./* w w w .jav a2s . com*/ * * @param source * a source of LegendItems */ public SimpleLegendTitle(LegendItemSource source) { super(source, new FlowArrangement(), new ColumnArrangement()); }
From source file:edu.cudenver.bios.chartsvc.representation.LegendImageRepresentation.java
/** * Called internally by Restlet library to write the image as the HTTP * response.// w ww. j a v a 2s . c o m * @param out output stream */ @Override public void write(OutputStream out) throws IOException { // build the legend from the plot, and write it to a jpeg image if (plot != null) { LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()); legend.setFrame(BlockBorder.NONE); //legend.setMargin(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); Rectangle2D.Double legendArea = new Rectangle2D.Double(0, 0, width, height); g.clip(legendArea); legend.arrange(g, new RectangleConstraint(width, height)); legend.draw(g, legendArea); g.dispose(); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out); } }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java
public void createChart() { XYPlot xyplot = (XYPlot) report.getPlot(); // if (this.decoratedChart instanceof TimeChartRenderer ) { if (this.results != null && !this.results.isEmpty()) { Iterator iter1 = this.results.iterator(); ValueMarker valuemarker = null;//www. j av a 2s.co m BlockContainer blockcontainerLabel = new BlockContainer(new ColumnArrangement()); // blockcontainerLabel.setFrame( new LineBorder() ); int i = 0; while (iter1.hasNext()) { Object[] item = (Object[]) iter1.next(); Date date = (Date) item[1]; Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); valuemarker = new ValueMarker(cal.getTimeInMillis(), ChartColor.createDefaultPaintArray()[i], new BasicStroke(2.0F)); xyplot.addDomainMarker(valuemarker); LegendItem legendLabel = new LegendItem((String) item[0], null, null, null, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), valuemarker.getPaint(), valuemarker.getStroke(), valuemarker.getPaint()); blockcontainerLabel.add(createLegendItemBlock(legendLabel, i)); i++; } createLegendBlock(blockcontainerLabel); } // } }
From source file:com.ikon.servlet.admin.StatsGraphServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String action = WebUtils.getString(request, "action", "graph"); String type = WebUtils.getString(request, "t"); JFreeChart chart = null;//from ww w. j a v a 2 s . c o m updateSessionManager(request); try { if ("refresh".equals(action)) { new RepositoryInfo().runAs(null); ServletContext sc = getServletContext(); sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response); } else { response.setContentType("image/png"); OutputStream out = response.getOutputStream(); if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) { chart = repoStats(type); } else if (DISK.equals(type)) { chart = diskStats(); } else if (JVM_MEMORY.equals(type)) { chart = jvmMemStats(); } else if (OS_MEMORY.equals(type)) { chart = osMemStats(); } if (chart != null) { // Customize title font chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16)); // Match body { background-color:#F6F6EE; } chart.setBackgroundPaint(new Color(246, 246, 238)); // Customize no data PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data to display"); // Customize labels plot.setLabelGenerator(null); // Customize legend LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()); legend.setPosition(RectangleEdge.BOTTOM); legend.setFrame(BlockBorder.NONE); legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12)); chart.removeLegend(); chart.addLegend(legend); if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) { ChartUtilities.writeChartAsPNG(out, chart, 225, 225); } else { ChartUtilities.writeChartAsPNG(out, chart, 250, 250); } } out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.jaxzin.iraf.forecast.swing.JForecaster.java
@SuppressWarnings({ "FieldRepeatedlyAccessedInMethod" }) private void customizeChart(final JFreeChart chart) { // Set the transparency of the histogram bars // chart.getXYPlot().setForegroundAlpha(0.5f); // Lock the y-axis to 0.0->0.5 // Customize the y-logAxis logAxis = new LogarithmicAxis("Account Value"); logAxis.setAutoRange(true);//from w w w. ja v a 2 s . c o m logAxis.setAllowNegativesFlag(true); logAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance()); linearAxis = new NumberAxis("Account Value"); linearAxis.setAutoRange(true); linearAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance()); //noinspection ConditionalExpression chart.getXYPlot().setRangeAxis(controlPanel.isLogScale() ? logAxis : linearAxis); // Customize the legend (add title, reverse order, attach to right side) final BlockContainer legendWrap = new BlockContainer(); final Block title = new LabelBlock("Percentiles"); legendWrap.setArrangement(new ColumnArrangement()); legendWrap.add(title); final LegendTitle legendTitle = new LegendTitle(new ReversedLegendItemSource(chart.getXYPlot()), new ColumnArrangement(), new ColumnArrangement()); legendWrap.add(legendTitle); chart.getLegend().setWrapper(legendWrap); chart.getLegend().setPosition(RectangleEdge.RIGHT); // Customize the format of the tooltips chart.getXYPlot().getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("yyyy"), NumberFormat.getCurrencyInstance())); }
From source file:edu.cudenver.bios.chartsvc.resource.ScatterPlotResource.java
/** * Create a JFreeChart object from the chart specification. JFreechart provides * functionality to render 2D scatter plots as jpeg images * //from www . ja v a 2 s .c o m * @param chart chart specification object * @return JFreeChart object * @throws ResourceException */ private JFreeChart buildScatterPlot(Chart chart) throws ResourceException { ArrayList<LineStyle> lineStyleList = chart.getLineStyleList(); float dashedLength = 1.0f; float spaceLength = 1.0f; float thickness = 1.0f; // the first series is treated as the x values if (chart.getSeries() == null || chart.getSeries().size() <= 0) throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified"); // create the jfree chart series XYSeriesCollection chartData = new XYSeriesCollection(); // use a spline renderer to make the connecting lines smooth XYSplineRenderer rend = new XYSplineRenderer(); int seriesIdx = 0; for (Series series : chart.getSeries()) { XYSeries xySeries = new XYSeries(series.getLabel()); List<Double> xList = series.getXCoordinates(); List<Double> yList = series.getYCoordinates(); if (xList != null && yList != null && xList.size() == yList.size()) { for (int i = 0; i < xList.size(); i++) { xySeries.add(xList.get(i), yList.get(i)); } } if (seriesIdx >= 0 && seriesIdx < lineStyleList.size()) { LineStyle lineStyle = lineStyleList.get(seriesIdx); dashedLength = (float) lineStyle.getDashLength(); spaceLength = (float) lineStyle.getSpaceLength(); thickness = (float) lineStyle.getWidth(); } else { dashedLength = 1.0f; spaceLength = 1.0f; thickness = 1.0f; } // set the line style rend.setSeriesPaint(seriesIdx, Color.BLACK); if (seriesIdx >= 0) { /*rend.setSeriesStroke(seriesIdx, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {(float) seriesIdx, (float) 2*seriesIdx}, 0.0f));*/ rend.setSeriesStroke(seriesIdx, new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { dashedLength, spaceLength }, 0.0f)); } // add the series to the data set chartData.addSeries(xySeries); seriesIdx++; } // turn off shapes displayed at each data point to make a smooth curve rend.setBaseShapesVisible(false); // Create the line chart NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); if (chart.getXAxis() != null) { Axis xAxisSpec = chart.getXAxis(); xAxis.setLabel(xAxisSpec.getLabel()); if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) { xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax()); } } NumberAxis yAxis = new NumberAxis(); if (chart.getYAxis() != null) { Axis yAxisSpec = chart.getYAxis(); yAxis.setLabel(chart.getYAxis().getLabel()); if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) { xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax()); } } XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); JFreeChart renderedChart = new JFreeChart(chart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); renderedChart.setBackgroundPaint(Color.WHITE); if (chart.hasLegend()) { LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()); legend.setFrame(BlockBorder.NONE); legend.setPosition(RectangleEdge.BOTTOM); renderedChart.addLegend(legend); } return renderedChart; }
From source file:lucee.runtime.tag.Chart.java
private void setLegend(JFreeChart chart, Plot plot, Font font) { if (!showlegend) return;/*from w w w . j a v a 2s.c o m*/ Color bg = backgroundcolor == null ? databackgroundcolor : backgroundcolor; if (font == null) font = getFont(); LegendTitle legend = legendMultiLine ? new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()) : new LegendTitle(plot); legend.setBackgroundPaint(bg); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setWidth(chartwidth - 20);// geht nicht legend.setItemFont(font); legend.setItemPaint(foregroundcolor); //RectangleInsets labelPadding; legend.setItemLabelPadding(new RectangleInsets(2, 2, 2, 2)); legend.setBorder(0, 0, 0, 0); legend.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT); legend.setLegendItemGraphicPadding(new RectangleInsets(8, 10, 0, 0)); chart.addLegend(legend); }