Bug in CategoryPlot setOrientation VERTICAL with Gantt chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
MarkU
Posts: 6
Joined: Mon Nov 29, 2010 1:24 pm
antibot: No, of course not.

Bug in CategoryPlot setOrientation VERTICAL with Gantt chart

Post by MarkU » Mon Mar 14, 2011 1:50 pm

When the Plot orientation in the following Gantt chart is set to Horizontal, Tasks plot correctly against the date axis, but when switched to Vertical they plot 'backwards' in time - so 2012 appears as 2011 and Q3 appears as Q2. Toggle lines 38/39 of the following code to demonstrate :

Code: Select all

package my.packge;

import java.util.Date;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.GanttRenderer;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.Year;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.data.time.Quarter;

public class GanttDrag1 extends ApplicationFrame {

    ChartPanel localChartPanel = null;
    JFreeChart jfreechart = null;
    TaskSeries sP = new TaskSeries("sP");
    TaskSeriesCollection datasetTSC = createSampleDataset(); 

    public GanttDrag1(final String title) { 

        super(title);
        // create chart
        DateAxis va = createDateAxis1();
        CategoryAxis ca = createCategoryAxis();
        GanttRenderer r = new GanttRenderer();
        CategoryPlot p = new CategoryPlot(datasetTSC, ca, va, r);
        p.setDataset(datasetTSC);
        p.setOrientation(PlotOrientation.HORIZONTAL); // HORIZONTAL PLOTS OK
        p.setOrientation(PlotOrientation.VERTICAL); //VERTICAL CONTAINS ERROR ? PLOTS BACWARDS IN TIME
        jfreechart = new JFreeChart(p);
        // add  chart to a panel...
        localChartPanel = new ChartPanel(jfreechart);
        localChartPanel.setPreferredSize(new java.awt.Dimension(500, 500));
        setContentPane(localChartPanel);
    }


    private DateAxis createDateAxis1 (){
                DateAxis da = new DateAxis();
                da.setTickMarkPosition(DateTickMarkPosition.START);
                return da;
    }
    private CategoryAxis createCategoryAxis (){
                CategoryAxis ca = new CategoryAxis("label");
                return ca;
    }

    private TaskSeriesCollection createSampleDataset() { 
                final Task p1 = new Task( "Prop1", new Year(2007));
                sP.add(p1);
                final Task p2 = new Task( "Prop2", new Year(2012));
                sP.add(p2);
                final Task p22 = new Task( "q", new Quarter(3,2012));
                sP.add(p22);

                Date start = p2.getDuration().getStart(); System.out.println(" start " + start);
                Date end = p2.getDuration().getEnd(); System.out.println(" end " + end);
                final Task p23 = new Task( "q2", start, end);
                sP.add(p23);

                final TaskSeriesCollection collection = new TaskSeriesCollection();
                collection.add(sP);
                return collection;
    }

    public static void main(final String[] args) {
        final GanttDrag1 demo = new GanttDrag1("GanttDrag1");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);
    }
}

Locked