JFreeChart : How to display hours format on the y axis

天大地大妈咪最大 提交于 2019-12-05 17:58:22

You will need to set a FormatOverride on the axis.

Here is an example for both a NumberAxis and a DateAxis

XYPlot plot = (XYPlot) chart.getPlot();

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setNumberFormatOverride( new NumberFormat(){

    @Override
    public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
        return new StringBuffer(String.format("%f", number));
    }

    @Override
    public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
        return new StringBuffer(String.format("%f", number));
    }

    @Override
    public Number parse(String source, ParsePosition parsePosition) {
        return null;
    }

} );
DateAxis domainAaxis = (DateAxis) plot.getDomainAxis();
domainAaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!