使用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);