4

使用DateAxis它工作正常:

// From: 2/5/13 02:00:00 PM (+1), To: 2/5/13 03:00:00 PM (+1)
// Configuring dataset
Timezone tz = new SimpleTimeZone(1, "Test");
TimeSeriesCollection dataset = new TimeSeriesCollection(tz);
TimeSeries timeSeries = new TimeSeries("Series1");
...
timeSeries.add(new Millisecond(new Date(timestamp1), tz, locale), value1);
timeSeries.add(new Millisecond(new Date(timestamp2), tz, locale), value2);
timeSeries.add(new Millisecond(new Date(timestamp3), tz, locale), value3);
...
// Setting axis timezone
((DateAxis) chart.getXYPlot().getDomainAxis()).setTimeZone(tz);
((DateAxis) chart.getXYPlot().getDomainAxis()).setRange(new DateRange(
           from, to), true, true);

日期轴图表

但是,当我尝试对PeriodAxis执行相同操作时,它会显示不正确的时区。看起来它正在从我的计算机(-3)获取时区。

// From: 2/5/13 02:00:00 PM (+1), To: 2/5/13 03:00:00 PM (+1)
// Configuring dataset
Timezone tz = new SimpleTimeZone(1, "Test");
TimeSeriesCollection dataset = new TimeSeriesCollection(tz);
TimeSeries timeSeries = new TimeSeries("Series1");
...
timeSeries.add(new Millisecond(new Date(timestamp1), tz, locale), value1);
timeSeries.add(new Millisecond(new Date(timestamp2), tz, locale), value2);
timeSeries.add(new Millisecond(new Date(timestamp3), tz, locale), value3);
...
// Setting periodAxis
PeriodAxis periodaxis = new PeriodAxis("");

periodaxis.setFirst(new Millisecond(new Date(from), tz));
periodaxis.setLast(new Millisecond(new Date(to), tz));

periodaxis.setTimeZone(tz);

periodaxis.setRange(new DateRange(from, to), true, true);
periodaxis.setAutoRangeTimePeriodClass(Second.class);
PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2];
aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(
        org.jfree.data.time.Minute.class, new SimpleDateFormat("mm"));
aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(
        org.jfree.data.time.Hour.class, new SimpleDateFormat("HH"));
periodaxis.setLabelInfo(aperiodaxislabelinfo);

chart.getXYPlot().setDomainAxis(periodaxis);

周期轴图

4

1 回答 1

5

找到了两种方法来解决这个问题:

第一

设置时区SimpleDateFormat

...
SimpleDateFormat dfMin = new SimpleDateFormat("mm");
dfMin.setTimeZone(tz); // Setting timezone
PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2];
aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(
        org.jfree.data.time.Minute.class, dfMin);
SimpleDateFormat dfHour = new SimpleDateFormat("mm");
dfHour.setTimeZone(tz); // Setting timezone
aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(
        org.jfree.data.time.Hour.class, dfHour);
periodaxis.setLabelInfo(aperiodaxislabelinfo);
...

第二

也将此报告为错误,IMO 轴必须遵守periodaxis.setTimeZone(tz);指令。此行应添加到PeriodAxis.java

885        while (p.getFirstMillisecond() <= axisMax) {
886            float x = (float) valueToJava2D(p.getMiddleMillisecond(), dataArea,
887                    edge);
888            DateFormat df = this.labelInfo[band].getDateFormat();

               df.setTimeZone(timeZone); // Missing timezone setting

889            String label = df.format(new Date(p.getMiddleMillisecond()));
890            long first = p.getFirstMillisecond();
891            long last = p.getLastMillisecond();
892            if (last > axisMax) {
于 2013-02-06T14:21:54.533 回答