List of usage examples for org.jfree.chart.axis AxisSpace add
public void add(double space, RectangleEdge edge)
From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java
/** * @param folderToWrite Folder to write the resulted charts. * @param plots Collections of plots./*from w w w.j a v a 2s. c o m*/ * @param infoMap Map with additional plot info. * @param mode Generation mode. * @throws Exception If failed. */ private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots, Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception { ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); int idx = -1; while (true) { idx++; DefaultXYDataset dataSet = new DefaultXYDataset(); List<JFreeChartPlotInfo> infoList = new ArrayList<>(); String xAxisLabel = ""; String yAxisLabel = ""; String plotName = ""; int cnt = 0; for (List<PlotData> plotData0 : plots) { if (plotData0.size() <= idx) continue; PlotData plotData = plotData0.get(idx); dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data); xAxisLabel = plotData.xAxisLabel; yAxisLabel = plotData.yAxisLabel; plotName = plotData.plotName(); infoList.add(info(plotData.series(), mode)); } if (infoList.isEmpty()) break; JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet, PlotOrientation.VERTICAL, false, false, false); AxisSpace as = new AxisSpace(); as.add(150, RectangleEdge.LEFT); XYPlot plot = (XYPlot) chart.getPlot(); BasicStroke stroke = new BasicStroke(1); plot.setRenderer(renderer); plot.setBackgroundPaint(WHITE); plot.setRangeGridlinePaint(GRAY); plot.setDomainGridlinePaint(GRAY); plot.setFixedRangeAxisSpace(as); plot.setOutlineStroke(stroke); for (int i = 0; i < infoList.size(); i++) { Color color = PLOT_COLORS[i % PLOT_COLORS.length]; renderer.setSeriesPaint(i, color); renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness. infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2)); } ValueAxis axis = plot.getRangeAxis(); Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5); axis.setTickLabelFont(font); axis.setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getDomainAxis().setLabelFont(font); chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30))); File res = new File(folderToWrite, plotName + ".png"); ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info); infoMap.put(res.getAbsolutePath(), infoList); println("Chart is saved to file: ", res); } }
From source file:com.newatlanta.bluedragon.CategoryAxis.java
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) { // create a new space object if one wasn't supplied... if (space == null) { space = new AxisSpace(); }//from w ww .ja v a 2 s .co m // if the axis is not visible, no additional space is required... if (!isVisible()) { return space; } // calculate the max size of the tick labels (if visible)... double tickLabelHeight = 0.0; double tickLabelWidth = 0.0; if (isTickLabelsVisible()) { g2.setFont(getTickLabelFont()); AxisState state = new AxisState(); // we call refresh ticks just to get the maximum width or height if (RectangleEdge.isTopOrBottom(edge)) { // BEGIN fix for category labels that wrap // If space has been reserved to the left and right then we need to // reduce the plot area // by this amount so that the space needed by category labels that wrap // on to multiple lines // will be calculated properly. Rectangle2D newPlotArea = new Rectangle2D.Double(plotArea.getX(), plotArea.getY(), plotArea.getWidth() - space.getLeft() - space.getRight(), plotArea.getHeight()); refreshTicks(g2, state, newPlotArea, edge); // END fix for category labels that wrap } else { refreshTicks(g2, state, plotArea, edge); } if (edge == RectangleEdge.TOP) { tickLabelHeight = state.getMax(); } else if (edge == RectangleEdge.BOTTOM) { tickLabelHeight = state.getMax(); } else if (edge == RectangleEdge.LEFT) { tickLabelWidth = state.getMax(); } else if (edge == RectangleEdge.RIGHT) { tickLabelWidth = state.getMax(); } } // get the axis label size and update the space object... Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge); double labelHeight = 0.0; double labelWidth = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { labelHeight = labelEnclosure.getHeight(); space.add(labelHeight + tickLabelHeight + this.getCategoryLabelPositionOffset(), edge); } else if (RectangleEdge.isLeftOrRight(edge)) { labelWidth = labelEnclosure.getWidth(); space.add(labelWidth + tickLabelWidth + this.getCategoryLabelPositionOffset(), edge); } return space; }