diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java index abc616e7415421094fbbd75bbfde4b8c278f7f58..57308563659c5146bee361d7090b0e0f01de25a8 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java @@ -51,8 +51,8 @@ public class DateChart08 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().width(800).height(600).title("Rotated Tick Labels").build(); chart.getStyleManager().setLegendVisible(false); - chart.getStyleManager().setXAxisLabelRotation(45); - + chart.getStyleManager().setXAxisLabelRotation(60); + chart.getStyleManager().setDatePattern("yyyy-MM-dd"); // generate data List<Date> xData = new ArrayList<Date>(); List<Double> yData = new ArrayList<Double>(); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index c65cc272bb9a0de2c162733e656269ef5e852af0..a4161641aa61777c0e76e73eb5f6bd19ffb00b1c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -227,7 +227,14 @@ public class Axis implements ChartPart { ; - double height = this.getXAxisHeightHint(width); + // double height = this.getXAxisHeightHint(width); + // System.out.println("height: " + height); + // the Y-Axis was already draw at this point so we know how much vertical room is left for the X-Axis + double height = + getChartPainter().getHeight() - axisPair.getYAxis().getBounds().getY() - axisPair.getYAxis().getBounds().getHeight() - getChartPainter().getStyleManager().getChartPadding() + - getChartPainter().getStyleManager().getPlotPadding(); + // System.out.println("height2: " + height2); + Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); // the paint zone @@ -249,8 +256,8 @@ public class Axis implements ChartPart { /** * The vertical Y-Axis is drawn first, but to know the lower bounds of it, we need to know how high the X-Axis paint zone is going to be. Since the tick labels could be rotated, we need to actually - * determine the tick labels first to get an idea of how tall thew X-Axis tick labels will be. - * + * determine the tick labels first to get an idea of how tall the X-Axis tick labels will be. + * * @return */ private double getXAxisHeightHint(double workingSpace) { @@ -271,11 +278,9 @@ public class Axis implements ChartPart { AxisTickCalculator axisTickCalculator = axisTick.getAxisTickCalculator(workingSpace); String sampleLabel = axisTickCalculator.getTickLabels().get(0); - // String tickLabel = - // getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ? new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0"; TextLayout textLayout = new TextLayout(sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); AffineTransform rot = - getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); Shape shape = textLayout.getOutline(rot); Rectangle2D rectangle = shape.getBounds(); axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength();