Week RegularTimePeriod - DateAxis formatting problems

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jmorrey
Posts: 1
Joined: Mon Apr 21, 2014 11:47 pm
antibot: No, of course not.

Week RegularTimePeriod - DateAxis formatting problems

Post by jmorrey » Tue Apr 22, 2014 12:04 am

I'm a JFreeChart newbie and I'm having trouble formatting a DateAxis while using the Week RegularTimePeriod.

I'd like to produce a chart that has one tick mark per week (interval of 7 days). I'd like the label for each tick mark to be the *Saturday* (dd-MMM format) ending the week. Most importantly, I'd like my datapoints to line up with these labels correctly.

Instead, the default seems to be an interval of 15 days or so and the datapoints seem to align with the first day of the week (Sunday) instead of the last. Can somebody help me with this?

My code is as follows:

Code: Select all

    
    TimeSeries ts = new TimeSeries("data");
    for(int i=1; i<=16; i++){
      Week week = new Week(i, 2014);
      double value = i*Math.random();
      ts.add(week, value);
    }
    TimeSeriesCollection tsc = new TimeSeriesCollection(ts);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            null,
            null,
            null,
            tsc,
            true,
            false,
            false
    );

    File output = new File("test.png");
    ChartUtilities.saveChartAsPNG(output, chart, 648, 348);
BTW: A nice enhancement to JFreeChart would be for it to recognize when you are using the "Week" RegularTimePeriod and automatically provide more reasonable defaults for the layout.

Locked