Gantt Chart - set fixed range for 1 year

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Posts: 1
Joined: Fri Aug 21, 2020 12:27 pm
antibot: No, of course not.

Gantt Chart - set fixed range for 1 year

Post by vicinl » Fri Aug 21, 2020 12:46 pm

Hello everybody,
I have created a simple Gantt Chart where I have a variable list of items, with a start and end date associated to each of them (format yyyy-MM-dd).
When I am displaying these items on a Gantt chart, I would like the x-axis (timeline) to display only years on the X-axis.

So far, if I have many items in the Chart (~100), items are displayed correctly per year.
When the number of items is reduced (say 20 items only), months+years are show and the chart is no longer legible.

Do you know how to force the chart to always show years only ?

Here's my code

Code: Select all

TaskSeries series = new TaskSeries ("Programmes")

for (Programme p: filteredProgrammes)
	series.add(new Task(p.getName(),p.getStartDate() ,p.getEndDate()));

 TaskSeriesCollection dataset = new TaskSeriesCollection();
        JFreeChart chart = ChartFactory.createGanttChart(
                "Roadmap", // Chart title
                "Programmes", // X-Axis Label
                "Timeline", // Y-Axis Label

          roadmapChartPanel = new ChartPanel(chart);
          roadmapChartPanel.setPreferredSize(new Dimension(ROADMAP_CHART_WIDTH, chartSize));

Post Reply