2
votes

I am using JFreeChart to display a value for each day of a month. Now I want to have my x-axis display the weeks in a month instead of the days. At the moment the values for my graph are double on the y-axis and int on the x axis.

Timestamp ts = a.getTimestamp(); Double val = a.getVal(); series1.add(ts.getDate(), val);

I am using plot.getDomainAxis().setRange(0, 31); to set the range for the days to one month and xax.setTickUnit(new NumberTickUnit(7)); for the x-axis to display the ticks at the right position. Instead of displaying the days (0, 7, 14, 21, 28) i want them to be weeks (0, 1, 2, 3, 4).

Is that even possible, and how would I be able to do that?

1

1 Answers

1
votes

You should use a DateAxis for your time axis, like ChartFactory.createTimeSeriesChart() does. Then you can use setDateFormatOverride(), like they show here, and the SimpleDateFormat for "week in month."

JFreeChart chart = ChartFactory.createTimeSeriesChart(…);
DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("W"));