final JFreeChart chart = ChartFactory.createLineChart(null, // chart title ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
/** * Shrinks the given rectangle by the amount of these insets. * * @param area the area (<code>null</code> not permitted). */ public void trim(final Rectangle2D area) { final double w = area.getWidth(); final double h = area.getHeight(); final double l = calculateLeftInset(w); final double r = calculateRightInset(w); final double t = calculateTopInset(h); final double b = calculateBottomInset(h); area.setRect(area.getX() + l, area.getY() + t, w - l - r, h - t - b); }
final RectangleAnchor anchor) { final Size2D d1 = this.textBlock.calculateDimensions(g2); final double w = this.interiorGap.extendWidth(d1.getWidth()); final double h = this.interiorGap.extendHeight(d1.getHeight()); final Size2D d2 = new Size2D(w, h); final Rectangle2D bounds = RectangleAnchor.createRectangle(d2, x, y, anchor); double xx = bounds.getX(); double yy = bounds.getY(); bounds.getWidth(), bounds.getHeight()); g2.setPaint(this.shadowPaint); g2.fill(shadow); g2.setPaint(this.backgroundPaint); g2.fill(bounds); (float) (xx + this.interiorGap.calculateLeftInset(w)), (float) (yy + this.interiorGap.calculateTopInset(h)), TextBlockAnchor.TOP_LEFT);
double bottomMargin = 0.0; if (vertical) { topMargin = calculateTopOutset(base.getHeight()); bottomMargin = calculateBottomOutset(base.getHeight()); leftMargin = calculateLeftOutset(base.getWidth()); rightMargin = calculateRightOutset(base.getWidth());
FontMetrics fm = g2.getFontMetrics(this.labelInfo[band].getLabelFont()); if (edge == RectangleEdge.BOTTOM) { delta1 = this.labelInfo[band].getPadding().calculateTopOutset( fm.getHeight()); delta1 = this.labelInfo[band].getPadding().calculateBottomOutset( fm.getHeight()); long axisMin = this.first.getFirstMillisecond(); long axisMax = this.last.getLastMillisecond(); g2.setFont(this.labelInfo[band].getLabelFont()); g2.setPaint(this.labelInfo[band].getLabelPaint()); Rectangle2D b2 = TextUtilities.getTextBounds(label2, g2, g2.getFontMetrics()); double w = Math.max(b1.getWidth(), b2.getWidth()); long ww = Math.round(java2DToValue(dataArea.getX() + w + 5.0, dataArea, edge)); if (isInverted()) { used += this.labelInfo[band].getPadding().calculateBottomOutset( fm.getHeight()); used += this.labelInfo[band].getPadding().calculateTopOutset( fm.getHeight());
PiePlotState state) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); RectangleInsets labelInsets = new RectangleInsets(UnitType.RELATIVE, 0.18, 0.18, 0.18, 0.18); Rectangle2D labelsArea = labelInsets.createInsetRectangle(pieArea); double runningTotal = 0.0; Iterator iterator = keys.iterator(); continue; g2.setFont(this.labelFont); FontMetrics fm = g2.getFontMetrics(); Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm); Rectangle2D out = this.labelPadding.createOutsetRectangle( bounds); Shape bg = ShapeUtilities.createTranslatedShape(out, x - bounds.getCenterX(), y - bounds.getCenterY()); if (this.labelShadowPaint != null) { Shape shadow = ShapeUtilities.createTranslatedShape(bg,
private RectangleInsets insets = new RectangleInsets(1, 1, 1, 1); public void draw(Graphics2D g2, Rectangle2D area) { Dimension arcs = new Dimension(45,45); double t = this.insets.calculateTopInset(area.getHeight()); double b = this.insets.calculateBottomInset(area.getHeight()); double l = this.insets.calculateLeftInset(area.getWidth()); double r = this.insets.calculateRightInset(area.getWidth()); double x = area.getX(); double w = area.getWidth(); double h = area.getHeight(); g2.setPaint(this.paint); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fill(myrect);
double w = area.getWidth(); double h = area.getHeight(); double t = this.insets.calculateTopInset(h); double b = this.insets.calculateBottomInset(h); double l = this.insets.calculateLeftInset(w); double r = this.insets.calculateRightInset(w); double x = area.getX(); double y = area.getY(); double x0 = x + l / 2.0; double y0 = y + h - b / 2.0; double y1 = y + t / 2.0; g2.setPaint(getPaint()); g2.setStroke(getStroke()); Line2D line = new Line2D.Double(); if (t > 0.0) { line.setLine(x0, y1, x1, y1); g2.draw(line);
topSpace = padding.calculateTopOutset(h); bottomSpace = padding.calculateBottomOutset(h); leftSpace = padding.calculateLeftOutset(w); rightSpace = padding.calculateRightOutset(w); startX = chartArea.getX() + leftSpace; startX = chartArea.getMaxX() - rightSpace - w; double startY = 0.0; if (alignment == VerticalAlignment.CENTER) { startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0; g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
throw new IllegalArgumentException("Null 'base' argument."); double x = base.getX(); double y = base.getY(); double w = base.getWidth(); double h = base.getHeight(); if (horizontal == LengthAdjustmentType.EXPAND) { final double leftOutset = calculateLeftOutset(w); x = x - leftOutset; w = w + leftOutset + calculateRightOutset(w); final double leftMargin = calculateLeftInset(w); x = x + leftMargin; w = w - leftMargin - calculateRightInset(w); final double topMargin = calculateTopOutset(h); y = y - topMargin; h = h + topMargin + calculateBottomOutset(h); final double topMargin = calculateTopInset(h); y = y + topMargin; h = h - topMargin - calculateBottomInset(h);
final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ChartUtil.adjustChebyshev(dataset, rangeAxis); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
CategoryAxis xAxis = (CategoryAxis) this.domainAxes.get(index); if (xAxis != null) { axisCollection.add(xAxis, getDomainAxisEdge(index)); ValueAxis yAxis = (ValueAxis) this.rangeAxes.get(index); if (yAxis != null) { axisCollection.add(yAxis, getRangeAxisEdge(index)); double cursor = dataArea.getMinY() - this.axisOffset.calculateTopOutset( dataArea.getHeight()); Iterator iterator = axisCollection.getAxesAtTop().iterator(); while (iterator.hasNext()) { cursor = dataArea.getMaxY() + this.axisOffset.calculateBottomOutset(dataArea.getHeight()); iterator = axisCollection.getAxesAtBottom().iterator(); while (iterator.hasNext()) { cursor = dataArea.getMinX() - this.axisOffset.calculateLeftOutset(dataArea.getWidth()); iterator = axisCollection.getAxesAtLeft().iterator(); while (iterator.hasNext()) { cursor = dataArea.getMaxX() + this.axisOffset.calculateRightOutset(dataArea.getWidth()); iterator = axisCollection.getAxesAtRight().iterator(); while (iterator.hasNext()) {
RectangleInsets s = new RectangleInsets(UnitType.RELATIVE, depth, depth, depth, depth); Rectangle2D innerArcBounds = new Rectangle2D.Double(); innerArcBounds.setRect(arcBounds); s.trim(innerArcBounds); Shape shadowArc = ShapeUtilities.createTranslatedShape( path, (float) shadowXOffset, (float) shadowYOffset); g2.setPaint(shadowPaint); g2.fill(shadowArc); g2.setPaint(paint); g2.fill(path); Paint outlinePaint = lookupSectionOutlinePaint(key);
JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(100); rangeAxis.setLowerBound(0); plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); plot.setDataset(1, buildComplexityDataSet(summaries));
private byte[] generateStackedAreaChart (CategoryDataset dataset, int width, int height) JFreeChart chart = ChartFactory.createStackedAreaChart (null, // chart title chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (true); plot.setDomainGridlinePaint (Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); BufferedImage img = chart.createBufferedImage (width, height);
JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setForegroundAlpha(0.7f); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.darkGray); domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setCategoryMargin(0.0); plot.setDomainAxis(domain); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRange(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryItemRenderer renderer = plot.getRenderer(); plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));
JFreeChart chart = ChartFactory.createBarChart ( chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); plot.setForegroundAlpha (0.7f); plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint (Color.lightGray); plot.setDomainGridlinesVisible (false); plot.setRangeGridlinesVisible (true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin (0); domainAxis.setLowerMargin (0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.20); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); BarRenderer renderer = (BarRenderer) plot.getRenderer();
private byte[] generateBoxAndWhiskerChart (BoxAndWhiskerCategoryDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createBoxAndWhiskerChart (null, null, null, dataset, false); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); CategoryPlot plot = (CategoryPlot) chart.getPlot (); plot.setDomainGridlinePaint (Color.white); plot.setDomainGridlinesVisible (true); plot.setRangeGridlinePaint (Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis (); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis (); domainAxis.setLowerMargin (0.0); domainAxis.setUpperMargin (0.0); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(false); plot.setBackgroundPaint(null); plot.setNoDataMessage("No data"); plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0, 20, 0, 20)); if (aMaxValue > 0) { plot.getRangeAxis().setRange(0.0, aMaxValue); ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0")); NumberAxis tick = new NumberAxis(); tick.setTickUnit(new NumberTickUnit(1)); standardUnits.add(tick.getTickUnit()); plot.getRangeAxis().setStandardTickUnits(standardUnits); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); chart.getCategoryPlot().setRenderer(renderer);
chart = ChartFactory.createXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false); ((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true); chart = ChartFactory.createStackedXYAreaChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false); chart = ChartFactory.createXYLineChart("", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false); chart.getXYPlot().setRenderer(renderer); chart.setAntiAlias(true); chart.setBackgroundPaint(new Color(backgroundColor)); for (int i = 0; i < seriesMaxCount; i++) { chart.getXYPlot().setDomainAxis(0, new DateAxis()); chart.getXYPlot().setDomainAxis(1, new DateAxis()); chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));