我有一个漂亮迷人的JFreeChart生成折线图,但有一个例外 - 在我的X轴的最后一个值是越来越截断,就像这样:JFreeChart的最后X轴标签切断
| | |_________|________|__________|_________|_________| 100 Hz 1 kHz 10 kHz 100 kHz 1 MHz 10 MH
(注意以MHz为单位的z被截断)。
我进去看了这里的解决方案:
JFreeChart tick label cut off
,但因为我手动指定在LogAxis
的范围内它从设定保证金没有任何效果的JavaDoc出现。
JavaDoc
这是我使用生成我X轴代码:
final LogAxis domainAxis = new LogAxis(frequencyAxisLabel); domainAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH)); domainAxis.setRange(100, 10000000); //100Hz to 10MHz domainAxis.setUpperMargin(.05); //Has no effect domainAxis.setNumberFormatOverride(new UnitNumberFormat(UnitValue.HERTZ)); plot.setDomainAxis(domainAxis);
如果有帮助,我使用下面还写这一个.svg文件:
// Get a DOMImplementation and create an XML document DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(document); svgGenerator.setSVGCanvasSize(new Dimension(720, 470)); // draw the chart in the SVG generator Rectangle bounds = new Rectangle(10, 10, 700, 450); chart.draw(svgGenerator, bounds); // Write svg file OutputStream outputStream = new FileOutputStream(new File("SomePath)); Writer out = new OutputStreamWriter(outputStream, "UTF-8"); svgGenerator.stream(out, true /* use css */); outputStream.flush(); outputStream.close();
鉴于setUpperMargin()方法不会产生效果,我该如何去确保标签有足够的空间来完全打印?我打开旋转刻度标签,但我还没有想出如何做到这一点,只有如何旋转轴标签。