#969 TimeTableXYDataset: period Month: labels shifted by 1 month

open
nobody
None
5
2012-11-27
2009-11-17
m.hilpert
No

To support multiple bars in a chart with a time axis, I had to change the dataset to the new TimeTableXYDataset structure. But now the time axis shows the labels shifted to the right! I.e. the tick for February now displays "January", etc. :(

The values are

2008-12-31 100.0
2009-01-31 105.7
2009-02-28 103.25
...

But the tick label for the second value (105.7) was "December 08" instead of "January 09"!

I browsed the Month.class of JFreeChart and see lots of +1 / -1 changes of month values.
I had to workaround this with a special case when using the Month period by adding 1 month for each date :?

After this workaround, the second value (105.7) then correctly shows "January 09", with trailing labels also correctly shifted backwards.

Discussion

  • m.hilpert

    m.hilpert - 2009-11-18

    Test code that shows the problem.

     
  • m.hilpert

    m.hilpert - 2009-11-18

    The attached test code shows the problem. I have seen thet the usage of the second method (getTickUnitSource()) introduces this problem. But this method is required to solve another problem as discussed in [url=http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=5722&hilit=TickUnitSource]TickUnitSource: endless instances to avoid overlapping?[/url] :(

     
  • m.hilpert

    m.hilpert - 2009-11-18

    Without the second method and using setDateFormatOverride() instead, the problem still persists:

    [code]
    /**
    * JFreeChart bug: TimeTableXYDataset with Month period shifts date tick labels.
    * (Bug <a href="http://sourceforge.net/tracker/?func=detail&aid=2899145&group_id=15494&atid=115494">2899145</a>)
    *
    * @return JFreeChart.
    */
    private JFreeChart testTimeTableXYDataset() {
    JFreeChart result = null;

    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setLenient(false); //strict parsing

    final TimeTableXYDataset ds = new TimeTableXYDataset();
    ds.add(new Month(sdf.parse("2006-05-31", new ParsePosition(0))), 100.0, "Series1");
    ds.add(new Month(sdf.parse("2006-05-31", new ParsePosition(0))), 100.0, "Series2");

    ds.add(new Month(sdf.parse("2006-06-30", new ParsePosition(0))), 100.0, "Series1");
    ds.add(new Month(sdf.parse("2006-06-30", new ParsePosition(0))), 100.0, "Series2");

    ds.add(new Month(sdf.parse("2006-07-31", new ParsePosition(0))), 100.0, "Series1");
    ds.add(new Month(sdf.parse("2006-07-31", new ParsePosition(0))), 99.77, "Series2");

    result = ChartFactory.createTimeSeriesChart("Time Chart", "Months", "Bars", ds, true, true, false);

    final XYPlot xyPlot = result.getXYPlot();
    final DateAxis da = (DateAxis) xyPlot.getDomainAxis();
    da.setTickMarkPosition(DateTickMarkPosition.END);

    //da.setStandardTickUnits(getTickUnitSource(new Month(), "MMM yyyy", null));
    final SimpleDateFormat sdf2 = new SimpleDateFormat("MMM yyyy");
    da.setDateFormatOverride(sdf2);

    return result;
    }//testTimeTableXYDataset()
    [/code]

    The first date value is "2006-05-31" which is March. But the chart shows "Apr 2006" for the first value(s).

     

Log in to post a comment.