jfree / jfreechart

A 2D chart library for Java applications (JavaFX, Swing or server-side).
http://www.jfree.org/jfreechart/
GNU Lesser General Public License v2.1
1.22k stars 463 forks source link

The X-axis chart of the DST is not displayed. #323

Open boyqian opened 2 years ago

boyqian commented 2 years ago

Incorrect description The X-axis chart of the DST is incorrect.

Copy

The environment time is Sydney DST. Transfer Start DST Timestamp 1680363293000 Sun Apr 2 02:34:53 AEDT 2023 Transfer end DST timestamp 1680366053000 Sun Apr 2 02:20:53 AEST 2023 Expected Behavior The X-axis time information is displayed correctly.

Screenshot Blank is not displayed. Some Picture can not upload........

* System (please fill in the following information): *

Operating system: Euler Font used: Other Contexts; TimeSeriesCollection xySeriesCollection = new TimeSeriesCollection(); TimeSeries series = new TimeSeries(“seriesName”); xySeriesCollection .addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, null, null, xySeriesCollection, true, false, false); XYPlot plot = new XYPlot(); ValueAxis valueAxis = plot.getRangeAxis(); Range range = valueAxis.getRange(); double lowerBonder = 0d; double upperBonder = range.getUpperBound();

    upperBonder = upperBonder < 1 ? 1 : upperBonder;
    Range newRange = new Range(lowerBonder, upperBonder);
    valueAxis.setAutoRange(false);
    valueAxis.setRange(newRange);

    DateAxis axis = new DateAxis();
    axis = (DateAxis) plot.getDomainAxis();
    axis.setRangeWithMargins(startTime, endTime); // that time
    axis.setLowerMargin(X_AXIS_ALIGN);
    axis.setUpperMargin(X_AXIS_ALIGN);
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    axis.setAutoRange(false);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.pink);
    plot.setRangeGridlinePaint(Color.pink);
    plot.setBackgroundAlpha(BACKGROUND_ALPHA);
    plot.setForegroundAlpha(BACKGROUND_ALPHA);

ChartUtils.saveChartAsPNG(new File(“fileName”), chart, 1200, 360); // and picture's X-axis chart of the DST is not displayed.

I has used 1.5.1 JfreeChart

trashgod commented 2 years ago

For reference, using your timestamps and this epoch converter, I see the following event having a duration of 46 minutes; it looks like the event spans the return to standard time in Sydney.

Start: Saturday, April 01, 2023 03:34:53 PM GMT
  End: Saturday, April 01, 2023 04:20:53 PM GMT
Start: Sunday,   April 02, 2023 02:34:53 AM AEDT
  End: Sunday,   April 02, 2023 02:20:53 AM AEST
boyqian commented 2 years ago

I tried to use the latest version of 1.5.3 to no avail. So could that be a problem~?

boyqian commented 2 years ago

Second second = new Second(new Date(time), TimeZone.getDefault(), Locale.getDefault()); The reason is that the current time zone is used after the DST. Can the Date object be changed to the DateTimeZone object next time?

trashgod commented 2 years ago

Can you get the desired result using setDateFormatOverride()?