JFreeChart:如何在y轴上显示小时格式 [英] JFreeChart : How to display hours format on the y axis

查看:173
本文介绍了JFreeChart:如何在y轴上显示小时格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何修改y轴的标签。
现在我使用一个TimeSeries和MINUTE类,然后将TimeSeries插入到一个Dataset中。
它看起来像这样:

I can't find how to modify the label of the y axis. For now I use a TimeSeries with the MINUTE class, and then insert the TimeSeries into a Dataset. It look like this :

   final TimeSeries s1 = new TimeSeries("Importation Time", Minute.class);
   s1.add(new Minute(dateFinal),concateHourAndMinuteToGetASingleValue);
   dataset.addSeries(s1);

我想要做的是修改显示标签,并放一个String(05h20 for exemple )

What I would like to do is to modify the display label, and put a String (05h20 for exemple) instead of the Double value.

任何帮助将非常感谢:)

Any help would be much appreciated :)

谢谢! p>

Thank you!

推荐答案

您需要在 FormatOverride > axis 。

You will need to set a FormatOverride on the axis.

下面是一个 NumberAxis c $ c> DateAxis

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"));

这篇关于JFreeChart:如何在y轴上显示小时格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆