List of usage examples for org.jfree.chart.block BlockContainer BlockContainer
public BlockContainer(Arrangement arrangement)
From source file:org.jfree.chart.demo.LegendWrapperDemo1.java
private static JFreeChart createChart(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart("Legend Wrapper Demo 1", piedataset, false, true, false);/*from w ww . ja va 2 s. c o m*/ PiePlot pieplot = (PiePlot) jfreechart.getPlot(); pieplot.setLabelFont(new Font("SansSerif", 0, 12)); pieplot.setNoDataMessage("No data available"); pieplot.setCircular(true); pieplot.setLabelGap(0.02D); LegendTitle legendtitle = new LegendTitle(jfreechart.getPlot()); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.setFrame(new BlockBorder(1.0D, 1.0D, 1.0D, 1.0D)); LabelBlock labelblock = new LabelBlock("Legend Items:", new Font("SansSerif", 1, 12)); labelblock.setPadding(5D, 5D, 5D, 5D); blockcontainer.add(labelblock, RectangleEdge.TOP); LabelBlock labelblock1 = new LabelBlock("Source: http://www.jfree.org"); labelblock1.setPadding(8D, 20D, 2D, 5D); blockcontainer.add(labelblock1, RectangleEdge.BOTTOM); BlockContainer blockcontainer1 = legendtitle.getItemContainer(); blockcontainer1.setPadding(2D, 10D, 5D, 2D); blockcontainer.add(blockcontainer1); legendtitle.setWrapper(blockcontainer); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); jfreechart.addSubtitle(legendtitle); return jfreechart; }
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 2 s .c om*/ 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:gda.plots.SimpleLegendTitle.java
/** * Overrides the super class method to create a SimpleLegendGraphic instead of a LegendGraphic and a * SimpleLegendLabelBlock instead of a LabelBlock (otherwise identical except private field names replaced with * method calls). Assumes it will be passed a SimpleLegendItem and uses it to get the SimpleXYSeries to pass on to * the SimpleLegendGraphic and SimpleLegendLabelBlock. * /*from www. j a va2 s . c o m*/ * @param item * the LegendItem for which the LegendItemBlock is to be created * @return the LegendItemBlock created */ @Override protected Block createLegendItemBlock(LegendItem item) { BlockContainer result = null; if (item instanceof SimpleLegendItem) { LegendGraphic lg = new SimpleLegendGraphic(item.getShape(), item.getFillPaint(), ((SimpleLegendItem) item).getSeries()); lg.setShapeFilled(item.isShapeFilled()); lg.setLine(item.getLine()); lg.setLineStroke(item.getLineStroke()); lg.setLinePaint(item.getLinePaint()); lg.setLineVisible(item.isLineVisible()); lg.setShapeVisible(item.isShapeVisible()); lg.setShapeOutlineVisible(item.isShapeOutlineVisible()); lg.setOutlinePaint(item.getOutlinePaint()); lg.setOutlineStroke(item.getOutlineStroke()); lg.setPadding(getLegendItemGraphicPadding()); BlockContainer legendItem = new BlockContainer(new BorderArrangement()); lg.setShapeAnchor(getLegendItemGraphicAnchor()); lg.setShapeLocation(getLegendItemGraphicLocation()); legendItem.add(lg, getLegendItemGraphicEdge()); LabelBlock labelBlock = new SimpleLegendLabelBlock(item.getLabel(), getItemFont(), getItemPaint(), ((SimpleLegendItem) item).getSeries()); labelBlock.setPadding(getItemLabelPadding()); labelBlock.setToolTipText(item.getLabel()); // labelBlock.setToolTipText("click"); legendItem.add(labelBlock); result = new BlockContainer(new CenterArrangement()); result.add(legendItem); } return result; }
From source file:org.gaixie.micrite.jfreechart.style.PieStyle.java
/** * ?2???block//from w ww. ja v a 2 s .c om * <p> * ? LegendTitle * @param chart JFreeChart */ public static void styleTwo(JFreeChart chart) { PiePlot plot = (PiePlot) chart.getPlot(); PieStyle.setBackground(chart); // LegendTitleblockblock BlockContainer block = new BlockContainer(new BorderArrangement()); block.setBorder(new BlockBorder(1.0D, 1.0D, 1.0D, 1.0D)); // LegendTitleblock LegendTitle legend = new LegendTitle(plot); BlockContainer legendBlock = legend.getItemContainer(); // legendBlockblock? block.add(legendBlock); legend.setWrapper(block); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); //label plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.SmartLegendTitle.java
private Block createDefaultLegendItem(LegendItem item) { BlockContainer result = null;// www .j a va2s. c o m Shape shape = item.getShape(); if (shape == null) { shape = new Rectangle(); } LegendGraphic lg = new LegendGraphic(shape, item.getFillPaint()); lg.setFillPaintTransformer(item.getFillPaintTransformer()); lg.setShapeFilled(item.isShapeFilled()); lg.setLine(item.getLine()); lg.setLineStroke(item.getLineStroke()); lg.setLinePaint(item.getLinePaint()); lg.setLineVisible(item.isLineVisible()); lg.setShapeVisible(item.isShapeVisible()); lg.setShapeOutlineVisible(item.isShapeOutlineVisible()); lg.setOutlinePaint(item.getOutlinePaint()); lg.setOutlineStroke(item.getOutlineStroke()); lg.setPadding(getLegendItemGraphicPadding()); LegendItemBlockContainer legendItem = new LegendItemBlockContainer(new BorderArrangement(), item.getDataset(), item.getSeriesKey()); lg.setShapeAnchor(getLegendItemGraphicAnchor()); lg.setShapeLocation(getLegendItemGraphicLocation()); legendItem.add(lg, getLegendItemGraphicEdge()); Font textFont = item.getLabelFont(); if (textFont == null) { textFont = getItemFont(); } Paint textPaint = item.getLabelPaint(); if (textPaint == null) { textPaint = getItemPaint(); } LabelBlock labelBlock = new LabelBlock(item.getLabel(), textFont, textPaint); labelBlock.setPadding(getItemLabelPadding()); legendItem.add(labelBlock); legendItem.setToolTipText(item.getToolTipText()); legendItem.setURLText(item.getURLText()); result = new BlockContainer(new CenterArrangement()); result.add(legendItem); return result; }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java
/** * Creates a legend item block./*from w w w . jav a2 s .c om*/ * * @param item * the legend item. * * @return The block. */ protected void createLegendBlock(BlockContainer blockcontainerLabel) { XYPlot xyplot = (XYPlot) report.getPlot(); int nbRenderer = xyplot.getDatasetCount(); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); if (nbRenderer > 1) { BlockContainer oldLegendBlockContainer = new BlockContainer( new FlowArrangement(HorizontalAlignment.LEFT, VerticalAlignment.TOP, 2.0D, 2.0D)); for (int i = 0; i < nbRenderer; i++) { LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(i)); legendtitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legendtitle.setFrame(new LineBorder()); legendtitle.setBackgroundPaint(ChartColor.WHITE); oldLegendBlockContainer.add(legendtitle); } blockcontainer.add(oldLegendBlockContainer, RectangleEdge.LEFT); } else { LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0)); legendtitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legendtitle.setFrame(new LineBorder()); legendtitle.setBackgroundPaint(ChartColor.WHITE); blockcontainer.add(legendtitle, RectangleEdge.LEFT); } LegendTitle legendtitle1 = new LegendTitle(xyplot.getRenderer()); legendtitle1.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legendtitle1.setFrame(new LineBorder()); legendtitle1.setBackgroundPaint(ChartColor.WHITE); legendtitle1.setWrapper(blockcontainerLabel); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(1000D, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); report.clearSubtitles(); report.addSubtitle(compositetitle); }
From source file:org.jfree.chart.demo.AnnotationDemo2.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset1(); JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); NumberAxis numberaxis1 = new NumberAxis("Secondary"); numberaxis1.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createDataset2()); xyplot.mapDatasetToRangeAxis(1, 1);/* w ww .ja v a 2 s .co m*/ XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D, 167.30000000000001D, -0.78539816339744828D); xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); xypointerannotation.setPaint(Color.red); xypointerannotation.setArrowPaint(Color.red); xylineandshaperenderer.addAnnotation(xypointerannotation); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true); xylineandshaperenderer1.setSeriesPaint(0, Color.black); xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D, 613.20000000000005D, 1.5707963267948966D); xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER); xylineandshaperenderer1.addAnnotation(xypointerannotation1); xyplot.setRenderer(1, xylineandshaperenderer1); LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer); LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:org.jfree.chart.demo.DualAxisDemo1.java
private static JFreeChart createChart() { JFreeChart jfreechart = ChartFactory.createBarChart("Dual Axis Chart", "Category", "Value", createDataset1(), PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(new Color(238, 238, 255)); categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryDataset categorydataset = createDataset2(); categoryplot.setDataset(1, categorydataset); categoryplot.mapDatasetToRangeAxis(1, 1); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); NumberAxis numberaxis = new NumberAxis("Secondary"); categoryplot.setRangeAxis(1, numberaxis); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0)); legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle.setFrame(new BlockBorder()); LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(1)); legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle1.setFrame(new BlockBorder()); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java
/** * *//*from w w w . j a va 2 s . c o m*/ public void createChart() { XYPlot xyplot = (XYPlot) report.getPlot(); if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) { Iterator iter = this.results.iterator(); TimeSeriesCollection defaultdataset = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("% success", Day.class); while (iter.hasNext()) { SurefireReportBean surefire = (SurefireReportBean) iter.next(); Date date = surefire.getDateGeneration(); s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT); } defaultdataset.addSeries(s1); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setSeriesPaint(0, ChartColor.DARK_BLUE); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(), NumberFormat.getPercentInstance(Locale.getDefault())); renderer.setBaseItemLabelGenerator(labelgenerator); renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE)); renderer.setBaseItemLabelsVisible(true); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT)); renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0)); legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle.setFrame(new BlockBorder()); legendtitle.setBackgroundPaint(ChartColor.WHITE); LegendTitle legendtitle1 = new LegendTitle(renderer); legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle1.setFrame(new BlockBorder()); legendtitle1.setBackgroundPaint(ChartColor.WHITE); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); report.clearSubtitles(); report.addSubtitle(compositetitle); xyplot.setDataset(1, defaultdataset); NumberAxis valueaxis = new NumberAxis("% success"); valueaxis.setLowerMargin(0.0D); valueaxis.setUpperMargin(AXIS_UPPER_MARGIN); valueaxis.setRangeWithMargins(0.0D, 1.0D); valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); xyplot.setRangeAxis(1, valueaxis); xyplot.mapDatasetToRangeAxis(1, 1); xyplot.setRenderer(1, renderer); } }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * /*from ww w . ja va 2s . c om*/ * @param title * the frame title. * @param strategyData * StrategyData */ public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) { this.strategyData = strategyData; this.setLayout(new BorderLayout()); // Used to mark the current price stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0); valueMarker = new ValueMarker(0.00, Color.black, stroke); this.chart = createChart(this.strategyData, title, tradingday); BlockContainer container = new BlockContainer(new BorderArrangement()); container.add(titleLegend1, RectangleEdge.LEFT); container.add(titleLegend2, RectangleEdge.RIGHT); container.add(new EmptyBlock(2000, 0)); CompositeTitle legends = new CompositeTitle(container); legends.setPosition(RectangleEdge.BOTTOM); this.chart.addSubtitle(legends); final ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseZoomable(true, true); chartPanel.setRefreshBuffer(true); chartPanel.setDoubleBuffered(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent e) { } public void chartMouseClicked(final ChartMouseEvent e) { CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); if (e.getTrigger().getClickCount() == 2) { double xItem = 0; double yItem = 0; if (e.getEntity() instanceof XYItemEntity) { XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity()); xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); } else { PlotEntity plotEntity = ((PlotEntity) e.getEntity()); XYPlot plot = (XYPlot) plotEntity.getPlot(); xItem = plot.getDomainCrosshairValue(); yItem = plot.getRangeCrosshairValue(); } for (XYPlot xyplot : subplots) { double x = xyplot.getDomainCrosshairValue(); double y = xyplot.getRangeCrosshairValue(); /* * If the cross hair is from a right-hand y axis we need * to convert this to a left-hand y axis. */ String rightAxisName = ", Price: "; double rangeLowerLeft = 0; double rangeUpperLeft = 0; double rangeLowerRight = 0; double rangeUpperRight = 0; double yRightLocation = 0; for (int index = 0; index < xyplot.getRangeAxisCount(); index++) { AxisLocation axisLocation = xyplot.getRangeAxisLocation(index); Range range = xyplot.getRangeAxis(index).getRange(); if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT) || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) { rangeLowerLeft = range.getLowerBound(); rangeUpperLeft = range.getUpperBound(); rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": "; } if (y >= range.getLowerBound() && y <= range.getUpperBound() && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT) || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) { rangeUpperRight = range.getUpperBound(); rangeLowerRight = range.getLowerBound(); } } if ((rangeUpperRight - rangeLowerRight) > 0) { yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft) * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight))); } else { yRightLocation = y; } String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName + new Money(y); if (x == xItem && y == yItem) { titleLegend1.setText(text); if (null == clickCrossHairs) { clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation); clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addAnnotation(clickCrossHairs); } else { clickCrossHairs.setText(text); clickCrossHairs.setX(x); clickCrossHairs.setY(yRightLocation); } } } } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) { for (XYPlot xyplot : subplots) { if (xyplot.removeAnnotation(clickCrossHairs)) { clickCrossHairs = null; titleLegend1.setText(" Time: 0, Price :0.0"); break; } } } } }); this.add(chartPanel, null); this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this); }