List of usage examples for org.jfree.chart.block BlockContainer BlockContainer
public BlockContainer(Arrangement arrangement)
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java
@SuppressWarnings("unchecked") @Override// ww w . j a va 2 s .co m public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP); boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class, DEFAULT_GRAPH_NO_DATA_MESSAGE); PieGraphData pieGraphData = makeDataSet(); Map<Comparable, Paint> colors = pieGraphData.colors; this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false); Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); this.chart.setBackgroundPaint(backgroundColor); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(plotColor); plot.setNoDataMessage(noDataMessage); if (!graphDisplayLabel) { plot.setLabelGenerator(null); } else { plot.setInteriorGap(0.001); plot.setMaximumLabelWidth(.3); // plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setShadowPaint(null); // plot.setOutlineVisible(false); //TODO use title font? Font font = plot.getLabelFont(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f)); plot.setLabelBackgroundPaint(labelColor); plot.setLabelShadowPaint(null); plot.setLabelOutlinePaint(null); plot.setLabelGap(0.001); plot.setLabelLinkMargin(0.0); plot.setLabelLinksVisible(true); // plot.setSimpleLabels(true); // plot.setCircular(true); } if (!graphBorder) { plot.setOutlineVisible(false); } if (title != null && !"".equals(title)) { TextTitle title1 = new TextTitle(); title1.setText(title); title1.setFont(titleFont); title1.setPadding(3, 2, 5, 2); chart.setTitle(title1); } else { chart.setTitle((TextTitle) null); } plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); //Makes a wrapper for the legend to remove the border around it if (legend) { LegendTitle legend1 = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legend1.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend1.setWrapper(wrapper); legend1.setPosition(RectangleEdge.BOTTOM); legend1.setHorizontalAlignment(HorizontalAlignment.CENTER); if (params.get(GraphSource.LEGEND_FONT) instanceof Font) { legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT))); } chart.addSubtitle(legend1); plot.setLegendLabelGenerator(new PieGraphLabelGenerator()); } for (Comparable category : colors.keySet()) { plot.setSectionPaint(category, colors.get(category)); } plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData)); plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData)); initialized = true; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.SmartLegendTitle.java
private Block createFlankedShapeLegendItem(FlankedShapeLegendItem item) { BlockContainer result = null;//from w w w. j a v a2 s . c o m LegendGraphic lg = new CustomLegendGraphic(item.getShape(), 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(this.getLegendItemGraphicPadding()); LegendItemBlockContainer legendItem = new LegendItemBlockContainer(new BorderArrangement(), item.getDataset(), item.getSeriesKey()); Font textFont = item.getLabelFont(); if (textFont == null) { textFont = getItemFont(); } Paint textPaint = item.getLabelPaint(); if (textPaint == null) { textPaint = getItemPaint(); } ColoredBlockContainer graphicsContainer = new ColoredBlockContainer(new Color(0, 0, 0, 0), new BorderArrangement()); LabelBlock labelBlock; Font smallerTextFont = textFont.deriveFont(textFont.getSize() * .8f); Font labelTextFont = textFont; labelBlock = new LabelBlock(item.getLeftShapeLabel(), smallerTextFont, textPaint); graphicsContainer.add(labelBlock, RectangleEdge.LEFT); graphicsContainer.add(lg, null); labelBlock = new LabelBlock(item.getRightShapeLabel(), smallerTextFont, textPaint); graphicsContainer.add(labelBlock, RectangleEdge.RIGHT); legendItem.add(graphicsContainer, getLegendItemGraphicEdge()); labelBlock = new LabelBlock(item.getLabel(), labelTextFont, 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./*w w w.j a v a 2s . c o m*/ * * @param item * the legend item. * * @return The block. */ protected Block createLegendItemBlock(LegendItem item, int i) { BlockContainer result = null; LegendGraphic lg = new LegendGraphic(item.getShape(), item.getFillPaint()); lg.setFillPaintTransformer(item.getFillPaintTransformer()); lg.setShapeFilled(true); lg.setLine(item.getLine()); lg.setLineStroke(item.getLineStroke()); lg.setLinePaint(item.getFillPaint()); lg.setLineVisible(true); lg.setShapeVisible(true); lg.setShapeOutlineVisible(true); lg.setOutlinePaint(item.getFillPaint()); lg.setOutlineStroke(item.getOutlineStroke()); lg.setPadding(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); LegendItemBlockContainer legendItem = new LegendItemBlockContainer(new BorderArrangement(), 0, i); lg.setShapeAnchor(RectangleAnchor.CENTER); lg.setShapeLocation(RectangleAnchor.CENTER); legendItem.add(lg, RectangleEdge.LEFT); LabelBlock labelBlock = new LabelBlock(item.getLabel(), new Font("SansSerif", Font.BOLD, 10), Color.black); labelBlock.setPadding(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); 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.ash.history.TopActivityPreview.java
/** * Add legend to chart panel./* w w w .j a va2s .c o m*/ * * @param fontSize */ public void addLegend(int fontSize) { LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0)); BlockContainer itemss = legend.getItemContainer(); itemss.setPadding(2, 10, 5, 2); wrapper.add(itemss); legend.setWrapper(wrapper); legend.setItemFont(new Font(LegendTitle.DEFAULT_ITEM_FONT.getFontName(), LegendTitle.DEFAULT_ITEM_FONT.getStyle(), fontSize)); legend.setPosition(RectangleEdge.RIGHT); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legend); }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartCategoryGraphSource.java
@Override public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL); String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL); CategoryDataset dataset = makeDataSet(); chart = createChart(title, xLabel, yLabel, dataset, false, false); // start customizing the graph Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET); Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class, backgroundColor);//from ww w . j a va 2s .c o m Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class, backgroundColor); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); chart.setBackgroundPaint(backgroundColor); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(plotColor); plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset)); plot.setDomainGridlinePaint(graphDomainGridlinePaint); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(graphRangeGridlinePaint); plot.setOutlineVisible(graphBorder); // set the axis location AxisLocation axisLocation = getParam(GraphSource.GRAPH_RANGE_AXIS_LOCATION, AxisLocation.class, AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(axisLocation); // customize the y-axis if (params.get(RANGE_AXIS) instanceof ValueAxis) { ValueAxis valueAxis = (ValueAxis) params.get(RANGE_AXIS); plot.setRangeAxis(valueAxis); } ValueAxis valueAxis = plot.getRangeAxis(); Object yAxisFont = params.get(GraphSource.GRAPH_Y_AXIS_FONT); Object yAxisLabelFont = params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT); Double rangeLowerBound = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, null); Double rangeUpperBound = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, null); boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false); boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class, true); if (yAxisFont instanceof Font) { valueAxis.setTickLabelFont((Font) yAxisFont); } if (yAxisLabelFont instanceof Font) { valueAxis.setLabelFont((Font) yAxisLabelFont); } if (rangeLowerBound != null) { valueAxis.setLowerBound(rangeLowerBound); } if (rangeUpperBound != null) { valueAxis.setUpperBound(rangeUpperBound); } if (graphRangeIntegerTick) { valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } valueAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible); // customize the x-axis if (params.get(DOMAIN_AXIS) instanceof CategoryAxis) { CategoryAxis domainAxis = (CategoryAxis) params.get(DOMAIN_AXIS); plot.setDomainAxis(domainAxis); } CategoryAxis domainAxis = plot.getDomainAxis(); Object xAxisFont = params.get(GraphSource.GRAPH_X_AXIS_FONT); Object xAxisLabelFont = params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT); if (xAxisFont instanceof Font) { domainAxis.setTickLabelFont((Font) xAxisFont); } if (xAxisLabelFont instanceof Font) { domainAxis.setLabelFont((Font) xAxisLabelFont); } domainAxis.setLabel(xLabel); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); // change the font of the graph title Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); TextTitle textTitle = new TextTitle(); textTitle.setText(title); textTitle.setFont(titleFont); chart.setTitle(textTitle); // makes a wrapper for the legend to remove the border around it boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); Object legendFont = params.get(GraphSource.LEGEND_FONT); if (legend) { LegendTitle legendTitle = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legendTitle.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legendTitle.setWrapper(wrapper); legendTitle.setPosition(RectangleEdge.BOTTOM); legendTitle.setHorizontalAlignment(HorizontalAlignment.CENTER); if (legendFont instanceof Font) { legendTitle.setItemFont((Font) legendFont); } chart.addSubtitle(legendTitle); } this.initialized = true; }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java
/** * Initializes the graph. This method generates the backing {@link JFreeChart} from the time series and graph * parameter data./*from w w w .j a va 2 s . c o m*/ * * @throws GraphException if the initialization fails */ public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL); String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL); Shape graphShape = getParam(GraphSource.GRAPH_SHAPE, Shape.class, DEFAULT_GRAPH_SHAPE); Paint graphColor = getParam(GraphSource.GRAPH_COLOR, Paint.class, DEFAULT_GRAPH_COLOR); boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP); Stroke graphStroke = getParam(GraphSource.GRAPH_STROKE, Stroke.class, DEFAULT_GRAPH_STROKE); Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET); checkSeriesType(data); @SuppressWarnings("unchecked") List<? extends TimeSeriesInterface> timeData = (List<? extends TimeSeriesInterface>) data; TimeSeriesCollection dataset = new TimeSeriesCollection(); int seriesCount = 1; for (TimeSeriesInterface series : timeData) { dataset.addSeries(buildTimeSeries(series, seriesCount)); seriesCount += 1; } // actually create the chart this.chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, false, graphToolTip, false); // start customizing it Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class, backgroundColor); Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class, backgroundColor); this.chart.setBackgroundPaint(backgroundColor); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(plotColor); plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset)); plot.setDomainGridlinePaint(graphDomainGridlinePaint); plot.setRangeGridlinePaint(graphRangeGridlinePaint); if (graphBorder) { } else { plot.setOutlinePaint(null); } //Use a TextTitle to change the font of the graph title TextTitle title1 = new TextTitle(); title1.setText(title); title1.setFont(titleFont); chart.setTitle(title1); //Makes a wrapper for the legend to remove the border around it if (legend) { LegendTitle legend1 = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legend1.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legend1.setWrapper(wrapper); legend1.setPosition(RectangleEdge.BOTTOM); legend1.setHorizontalAlignment(HorizontalAlignment.CENTER); if (params.get(GraphSource.LEGEND_FONT) instanceof Font) { legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT))); } chart.addSubtitle(legend1); } boolean include0 = getParam(GraphSource.GRAPH_RANGE_INCLUDE_0, Boolean.class, true); NumberAxis numAxis = (NumberAxis) plot.getRangeAxis(); double rangeLower = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, numAxis.getLowerBound()); double rangeUpper = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, numAxis.getUpperBound()); boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false); boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class, true); if (include0) { rangeLower = 0; } numAxis.setRange(rangeLower, rangeUpper); if (graphRangeIntegerTick) { numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible); setupFont(numAxis, GraphSource.GRAPH_Y_AXIS_FONT); if (params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT) instanceof Font) { numAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT))); } TimeResolution minimumResolution = getMinimumResolution(timeData); DateFormat dateFormat = getParam(GraphSource.GRAPH_DATE_FORMATTER, DateFormat.class, new DefaultDateFormatFactory().getFormat(minimumResolution)); if (params.get(DATE_AXIS) instanceof DateAxis) { DateAxis dateAxis = (DateAxis) params.get(DATE_AXIS); dateAxis.setLabel(xLabel); plot.setDomainAxis(dateAxis); } DateAxis dateAxis = ((DateAxis) plot.getDomainAxis()); dateAxis.setDateFormatOverride(dateFormat); if (params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT) instanceof Font) { dateAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT))); } int minTick = getParam(GraphSource.GRAPH_MIN_DOMAIN_TICK, Integer.class, 1); if (minTick <= 0) { minTick = 1; } dateAxis.setTickUnit(getDateTickUnit(minimumResolution, minTick), false, false); //dateAxis.setMinorTickMarksVisible(true); //dateAxis.setMinorTickCount(7); dateAxis.setMinorTickMarkOutsideLength(2); Integer minorTick = getParam(GraphSource.GRAPH_MINOR_TICKS, Integer.class, null); if (minorTick != null) { int minorVal = minorTick; if (minorVal > 0) { dateAxis.setMinorTickCount(minorVal); } } setupFont(dateAxis, GraphSource.GRAPH_X_AXIS_FONT); //double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN); double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN); dateAxis.setLowerMargin(lowerMargin); //double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN); double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN); dateAxis.setUpperMargin(upperMargin); Date domainLower = getParam(GraphSource.GRAPH_DOMAIN_LOWER_BOUND, Date.class, dateAxis.getMinimumDate()); Date domainUpper = getParam(GraphSource.GRAPH_DOMAIN_UPPER_BOUND, Date.class, dateAxis.getMaximumDate()); dateAxis.setRange(domainLower, domainUpper); // depending on the domain axis range, display either 1 tick per day, week, month or year TickUnits standardUnits = new TickUnits(); standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1)); standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7)); standardUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1)); standardUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1)); dateAxis.setStandardTickUnits(standardUnits); TimeSeriesRenderer renderer = new TimeSeriesRenderer(dataset); setupRenderer(renderer, graphColor, graphShape, graphStroke); renderer.setBaseFillPaint(Color.BLACK); renderer.setSeriesOutlinePaint(0, Color.WHITE); //renderer.setUseOutlinePaint(true); plot.setRenderer(renderer); this.initialized = true; }
From source file:wsattacker.plugin.dos.dosExtension.chart.ChartObject.java
public JFreeChart createOverlaidChart() { // ---------------------------- // Data and X-Y-Axis - Response Time Testprobes // - Y-Achse 0 final DateAxis yAxis = new DateAxis("Time"); yAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); // - X-Achse 0 final NumberAxis xAxis0 = new NumberAxis("Response Time in ms"); xAxis0.setStandardTickUnits(NumberAxis.createStandardTickUnits()); // xAxis0.setTickUnit( new NumberTickUnit(1) ); // - dataset//from w w w.j a va2 s. c o m // - renderer final XYDataset dataResponseTimeProbes = createDatasetResponseTime("testprobe"); final XYLineAndShapeRenderer rendererResponseTimeProbes = new XYLineAndShapeRenderer(); // StandardXYItemRenderer(); // -> // should // not // be // used rendererResponseTimeProbes.setSeriesPaint(0, Color.blue); rendererResponseTimeProbes.setSeriesShape(0, new Ellipse2D.Double(-1.5, -1.5, 3.0, 3.0)); rendererResponseTimeProbes.setSeriesLinesVisible(0, true); rendererResponseTimeProbes.setSeriesShapesVisible(0, true); rendererResponseTimeProbes.setUseOutlinePaint(false); rendererResponseTimeProbes.setSeriesOutlinePaint(0, Color.black); rendererResponseTimeProbes.setUseFillPaint(true); rendererResponseTimeProbes.setSeriesFillPaint(0, Color.blue); // ---------------------------- // NEW XYPlot (new "Data and X-Y-Axis" from above added as default) final XYPlot plot = new XYPlot(dataResponseTimeProbes, yAxis, xAxis0, rendererResponseTimeProbes); // ---------------------------- // Data and Axis 1 - Response time UNtampered // - Dataset // - Renderer. // - Dataset zu X-Axis 0 mappen final XYDataset dataResponseTimeUntampered = createDatasetResponseTime("untampered"); final XYLineAndShapeRenderer rendererResponseTimeUntampered = new XYLineAndShapeRenderer(); // StandardXYItemRenderer(); // -> // should // not // be // used rendererResponseTimeUntampered.setSeriesPaint(0, new Color(0, 161, 4)); rendererResponseTimeUntampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0)); rendererResponseTimeUntampered.setUseFillPaint(true); rendererResponseTimeUntampered.setSeriesFillPaint(0, Color.white); rendererResponseTimeUntampered.setUseOutlinePaint(false); rendererResponseTimeUntampered.setSeriesOutlinePaint(0, Color.black); rendererResponseTimeUntampered.setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); plot.setDataset(2, dataResponseTimeUntampered); plot.setRenderer(2, rendererResponseTimeUntampered); // plot.mapDatasetToRangeAxis(0, 1); // ---------------------------- // Data and Axis - Response time tampered // - Dataset // - Renderer // - Dataset zu X-Axis 2 mappen final XYDataset dataResponseTimeTampered = createDatasetResponseTime("tampered"); XYLineAndShapeRenderer rendererResponseTimeTampered = new XYLineAndShapeRenderer(); // XYSplineRenderer(); rendererResponseTimeTampered.setSeriesPaint(0, new Color(189, 0, 0)); rendererResponseTimeTampered.setSeriesShape(0, new Ellipse2D.Double(-4, -4, 8.0, 8.0));// (-2.5, -2.5, 6.0, // 6.0) ); rendererResponseTimeTampered.setUseFillPaint(true); rendererResponseTimeTampered.setSeriesFillPaint(0, Color.white); rendererResponseTimeTampered.setUseOutlinePaint(false); rendererResponseTimeTampered.setSeriesOutlinePaint(0, Color.black); plot.setDataset(3, dataResponseTimeTampered); plot.setRenderer(3, rendererResponseTimeTampered); // plot.mapDatasetToRangeAxis(0, 2); // ---------------------------- // Data and X-Axis - Number Requests UNtampered // - X-Axis Number Requests final NumberAxis xAxis1 = new NumberAxis( "Number Requests Per Interval (" + (model.getIntervalLengthReport() / 1000) + " sec)"); xAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // xAxis1.setTickUnit( new NumberTickUnit(2) ); plot.setRangeAxis(1, xAxis1); // - Dataset // - Renderer final IntervalXYDataset dataNumberRequestsUntampered = createDatasetNumberRequestsUntampered(); final XYBarRenderer rendererNumberRequestsUntampered = new XYBarRenderer(0.2); rendererNumberRequestsUntampered.setShadowVisible(false); rendererNumberRequestsUntampered.setBarPainter(new StandardXYBarPainter()); rendererNumberRequestsUntampered.setSeriesPaint(0, new Color(128, 255, 128)); plot.setDataset(4, dataNumberRequestsUntampered); plot.setRenderer(4, rendererNumberRequestsUntampered); plot.mapDatasetToRangeAxis(4, 1); // ------------------------------- // Data - Number Requests tampered // - Dataset // - Renderer final IntervalXYDataset dataNumberRequestsTampered = createDatasetNumberRequestsTampered(); final XYBarRenderer rendererBarNumberRequestsTampered = new XYBarRenderer(0.2); rendererBarNumberRequestsTampered.setShadowVisible(false); rendererBarNumberRequestsTampered.setBarPainter(new StandardXYBarPainter()); rendererBarNumberRequestsTampered.setSeriesPaint(0, new Color(255, 148, 148)); plot.setDataset(5, dataNumberRequestsTampered); plot.setRenderer(5, rendererBarNumberRequestsTampered); plot.mapDatasetToRangeAxis(5, 1); // ------------------------- // Other formating stuff // - add annotations // final double x = new Day(9, SerialDate.MARCH, // 2002).getMiddleMillisecond(); // final XYTextAnnotation annotation = new // XYTextAnnotation("Anmerkung zu Datenpunkt", x, 1000.0); // annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); // plot.addAnnotation(annotation); // ------------------------- // Create custom LegendTitles // Legend Row 1 LegendTitle legendL1 = new LegendTitle(plot.getRenderer(0)); legendL1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendL1.setBorder(0, 0, 0, 0); LegendTitle legendR1 = new LegendTitle(plot.getRenderer(4)); legendR1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendR1.setBorder(0, 0, 0, 0); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.setBorder(0, 0, 0, 0); blockcontainer.add(legendL1, RectangleEdge.LEFT); blockcontainer.add(legendR1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle1 = new CompositeTitle(blockcontainer); compositetitle1.setPosition(RectangleEdge.BOTTOM); // Legend Row 2 LegendTitle legendL2 = new LegendTitle(plot.getRenderer(2)); legendL2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendL2.setBorder(0, 0, 0, 0); LegendTitle legendR2 = new LegendTitle(plot.getRenderer(5)); legendR2.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendR2.setBorder(0, 0, 0, 0); BlockContainer blockcontainer2 = new BlockContainer(new BorderArrangement()); blockcontainer2.setBorder(0, 0, 0, 0); blockcontainer2.add(legendL2, RectangleEdge.LEFT); blockcontainer2.add(legendR2, RectangleEdge.RIGHT); blockcontainer2.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle2 = new CompositeTitle(blockcontainer2); compositetitle2.setPosition(RectangleEdge.BOTTOM); // Legend Row 3 LegendTitle legendL3 = new LegendTitle(plot.getRenderer(3)); legendL3.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendL3.setBorder(0, 0, 0, 0); BlockContainer blockcontainer3 = new BlockContainer(new BorderArrangement()); blockcontainer3.setBorder(0, 0, 0, 0); blockcontainer3.add(legendL3, RectangleEdge.LEFT); blockcontainer3.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle3 = new CompositeTitle(blockcontainer3); compositetitle3.setPosition(RectangleEdge.BOTTOM); // ------------------------- // create Chart // - return a new chart containing the overlaid plot... plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart jFreeChart = new JFreeChart(model.getAttackName() + " - Response Time Plot", // Roundtrip Time Plot JFreeChart.DEFAULT_TITLE_FONT, plot, true); // Add new legend boxes + format jFreeChart.addSubtitle(compositetitle1); jFreeChart.addSubtitle(compositetitle2); jFreeChart.addSubtitle(compositetitle3); // Surpress old Legends LegendTitle legendee2 = jFreeChart.getLegend(0); legendee2.setVisible(false); return jFreeChart; }
From source file:com.bt.aloha.sipstone.GenGraph.java
private JFreeChart createCombinedChart() { XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond(); XYDataset xydataset = xydatasetArray[0]; final XYDataset percXydataset = xydatasetArray[1]; JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = new NumberAxis("Avg. Response Time"); numberaxis.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis);/* w w w .j av a2 s . c om*/ xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime()); xyplot.mapDatasetToRangeAxis(1, 1); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setShapesFilled(true); } XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); xylineandshaperenderer1.setSeriesPaint(0, Color.black); xylineandshaperenderer1.setBaseShapesVisible(true); xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); xyplot.setRenderer(1, xylineandshaperenderer1); NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis(); timeaxis.setAutoRange(true); timeaxis.setAxisLineVisible(true); LegendTitle legendtitle = new LegendTitle(xyitemrenderer); 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)); XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer(); xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset)); xyrenderer.setBaseItemLabelsVisible(true); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:org.ash.gui.StackedChart.java
/** * Creates the chart.//www .ja va2 s .com * * @return the j free chart */ private JFreeChart createChart() { xAxis = new DateAxis("time"); xAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); currentDate = new Date(); updatexAxisLabel(new Long(currentDate.getTime()).doubleValue()); chart = ChartFactory.createStackedXYAreaChart("Top activity", // chart title "X Value", // domain axis label "Active Sessions", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation xAxis, false, // legend true, // tooltips false // urls ); plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer3 renderer = new StackedXYAreaRenderer3(); renderer.setRoundXCoordinates(true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})", new SimpleDateFormat("HH:mm"), new DecimalFormat("0.0"))); plot.setRenderer(0, renderer); plot.getRangeAxis().setLowerBound(0.0); plot.getRangeAxis().setAutoRange(true); // add a labelled marker for the cpu_count thresholdMaxCpu = new ValueMarker(this.maxCpu); thresholdMaxCpu.setLabelOffsetType(LengthAdjustmentType.EXPAND); thresholdMaxCpu.setPaint(Color.red); thresholdMaxCpu.setStroke(new BasicStroke(1.0f)); thresholdMaxCpu.setLabel("Maximum CPU"); thresholdMaxCpu.setLabelFont(new Font("SansSerif", Font.PLAIN, 11)); thresholdMaxCpu.setLabelPaint(Color.red); thresholdMaxCpu.setLabelAnchor(RectangleAnchor.TOP_LEFT); thresholdMaxCpu.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); plot.addRangeMarker(thresholdMaxCpu); renderer.setSeriesPaint(0, Options.getInstance().getColor(Options.getInstance().getResource("cpuLabel.text")), true); renderer.setSeriesPaint(1, Options.getInstance().getColor(Options.getInstance().getResource("schedulerLabel.text")), true); renderer.setSeriesPaint(2, Options.getInstance().getColor(Options.getInstance().getResource("userIOLabel.text")), true); renderer.setSeriesPaint(3, Options.getInstance().getColor(Options.getInstance().getResource("systemIOLabel.text")), true); renderer.setSeriesPaint(4, Options.getInstance().getColor(Options.getInstance().getResource("concurrencyLabel.text")), true); renderer.setSeriesPaint(5, Options.getInstance().getColor(Options.getInstance().getResource("applicationsLabel.text")), true); renderer.setSeriesPaint(6, Options.getInstance().getColor(Options.getInstance().getResource("commitLabel.text")), true); renderer.setSeriesPaint(7, Options.getInstance().getColor(Options.getInstance().getResource("configurationLabel.text")), true); renderer.setSeriesPaint(8, Options.getInstance().getColor(Options.getInstance().getResource("administrativeLabel.text")), true); renderer.setSeriesPaint(9, Options.getInstance().getColor(Options.getInstance().getResource("networkLabel.text")), true); renderer.setSeriesPaint(11, Options.getInstance().getColor(Options.getInstance().getResource("queueningLabel.text")), true);//que renderer.setSeriesPaint(10, Options.getInstance().getColor(Options.getInstance().getResource("clusterLabel.text")), true);//cluster renderer.setSeriesPaint(12, Options.getInstance().getColor(Options.getInstance().getResource("otherLabel.text")), true); // Set format for x axis DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); // Add legend to right LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0)); BlockContainer itemss = legend.getItemContainer(); itemss.setPadding(2, 10, 5, 2); wrapper.add(itemss); legend.setWrapper(wrapper); legend.setPosition(RectangleEdge.RIGHT); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legend); return chart; }
From source file:org.ash.history.detail.StackedChartDetail.java
/** * Creates the chart./*w ww . j a v a 2s .com*/ * * @return the jfreechart */ private JFreeChart createChart() { xAxis = new DateAxis("time"); xAxis.setLabel(null); chart = ChartFactory.createStackedXYAreaChart("", // chart title "X Value", // domain axis label "Active Sessions", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation xAxis, // xAxis false, // legend true, // tooltips false // urls ); chart.getTitle() .setFont(new Font(TextTitle.DEFAULT_FONT.getFontName(), TextTitle.DEFAULT_FONT.getStyle(), 14)); plot = (XYPlot) chart.getPlot(); renderer = new StackedXYAreaRenderer3(); renderer.setRoundXCoordinates(true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})", new SimpleDateFormat("HH:mm"), new DecimalFormat("0.0"))); plot.setRenderer(0, renderer); plot.getRangeAxis().setLowerBound(0.0); plot.getRangeAxis().setAutoRange(true); // Set format for x axis DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); // Add legend to right LegendTitle legend = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0)); BlockContainer itemss = legend.getItemContainer(); itemss.setPadding(2, 10, 5, 2); wrapper.add(itemss); legend.setWrapper(wrapper); legend.setPosition(RectangleEdge.RIGHT); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(new Font(LegendTitle.DEFAULT_ITEM_FONT.getFontName(), LegendTitle.DEFAULT_ITEM_FONT.getStyle(), 10)); chart.addSubtitle(legend); return chart; }