Hi all
I have a gantt chart which i draw with JFreeChart.
I want to add to this grpah a line that shows the current date.
Does any 1 knows how to do it?
Here is the code that i've written:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GanttChart.java
 *
 * Created on 09/01/2010, 18:47:38
 */

package edel2;

import java.awt.BasicStroke;
import java.awt.Color;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JLabel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryMarker;
import org.jfree.chart.plot.Marker;
import org.jfree.data.category.IntervalCategoryDataset;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.SimpleTimePeriod;
import org.jfree.ui.Layer;


/**
 *
 * @author SEVER
 */
public class GanttChart extends javax.swing.JFrame {

public Project projects;

    /** Creates new form GanttChart */
    public GanttChart(Project pro) {
        initComponents();
        projects=pro;
        JLabel jLabel2 = new javax.swing.JLabel("End Date");
        gantPanel.add(jLabel2);
        final IntervalCategoryDataset dataset = createDataset();
        final JFreeChart chart = createChart(dataset);
        // add the chart to a panel...
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

        setContentPane(chartPanel);
    //    gantPanel.add(chartPanel);

    }

     public  IntervalCategoryDataset createDataset() {

        final TaskSeries s1 = new TaskSeries("Not Started");
        
        final TaskSeries s2 = new TaskSeries("Started");
        final TaskSeries s3 = new TaskSeries("Finished");
    //    String Name=projects.tasks.get(0).name;
        for(int i=0;i<projects.tasks.size();i++)
        {
            if(projects.tasks.get(i).status.completedPercent==0)
            {
                Task t1 = new Task(projects.tasks.get(i).name,projects.tasks.get(i).startDate,projects.tasks.get(i).endDate );
                        t1.setPercentComplete(0.0);
        //s1.add(new Task(projects.tasks.get(i).name,projects.tasks.get(i).startDate,projects.tasks.get(i).endDate));
           s1.add(t1);
            }
        else
            if(projects.tasks.get(i).status.completedPercent==50)
            {
        //        s2.add(new Task(projects.tasks.get(i).name,projects.tasks.get(i).startDate,projects.tasks.get(i).endDate));
             Task t1 = new Task(projects.tasks.get(i).name,projects.tasks.get(i).startDate,projects.tasks.get(i).endDate );
                        t1.setPercentComplete(0.5);
                        s2.add(t1);
            }
                else
            if(projects.tasks.get(i).status.completedPercent==100)
            {
              //  s3.add(new Task(projects.tasks.get(i).name,projects.tasks.get(i).startDate,projects.tasks.get(i).endDate));
                        Task t1 = new Task(projects.tasks.get(i).name,projects.tasks.get(i).startDate,projects.tasks.get(i).endDate );
                        t1.setPercentComplete(1.0);
                        s3.add(t1);

            }
        }
     //   final Task t1 = new Task(projects.tasks.get(0).name,projects.tasks.get(0).startDate,projects.tasks.get(0).endDate );
        //t1.setPercentComplete(0.5);
        //s3.add(t1);
        final TaskSeriesCollection collection = new TaskSeriesCollection();
        collection.add(s1);
        collection.add(s2);
        collection.add(s3);

        return collection;
    }

        
        private static Date makeDate(final int day, final int month, final int year) {

	final Calendar calendar = Calendar.getInstance();
	calendar.set(year, month, day);
	final Date result = calendar.getTime();
	return result;

	}
	/**Adding data in this series**/

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */

        private JFreeChart createChart(final IntervalCategoryDataset dataset) {
        final JFreeChart chart = ChartFactory.createGanttChart(
         projects.getName(),  // chart title
            "Task",              // domain axis label
            "Date",              // range axis label
            dataset,             // data
            true,                // include legend
            true,                // tooltips
            false                // urls
        );
//        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
        return chart;
    }




    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        gantPanel = new javax.swing.JPanel();

        javax.swing.GroupLayout gantPanelLayout = new javax.swing.GroupLayout(gantPanel);
        gantPanel.setLayout(gantPanelLayout);
        gantPanelLayout.setHorizontalGroup(
            gantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 668, Short.MAX_VALUE)
        );
        gantPanelLayout.setVerticalGroup(
            gantPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 396, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(gantPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(268, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(gantPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(175, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    /**
    * @param args the command line arguments
    */
   
    // Variables declaration - do not modify                     
    private javax.swing.JPanel gantPanel;
    // End of variables declaration                   

}

Hi,

i have the same problem. Do you find a solution to add the line that shows the current date?
Thanks,

Alex.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.