2
大家好,你好嗎?爲什麼不正確的數據出現在甘特圖中?
我做了一個java應用程序來管理任務,我打算創建子任務的甘特圖。
我做了以下,但數據顯示不正確。
正如你從我發佈的圖片中可以看到的,雖然它們出現3個小節,但僅顯示來自單個子任務的數據。沒有出現在左側。我不知道爲什麼會發生這種情況。
有沒有人可以幫我解決這個小問題?
結果查詢:
SubTask StartDate EndDate
T3.1 2014-04-29 2014-06-05
T3.2 2014-06-05 2014-06-05
T3.3 2014-06-09 2014-06-09
代碼
public class GantDemo {
private static Date date(int day, int month, int year) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
Date result = calendar.getTime();
return result;
}
public static void main(String[] args) {
Connection con = null;
TaskSeriesCollection collection = new TaskSeriesCollection();
/* MySQL */
String databaseURL = "jdbc:mysql://localhost:3306/tasks1.5";
String driverName = "com.mysql.jdbc.Driver";
String user = "****";
String password = "*****";
try {
Class.forName(driverName).newInstance();
} catch (Exception ex) {
System.out.println("");
}
try {
con = DriverManager.getConnection(databaseURL, user, password);
if (!con.isClosed()) {
System.out.println("Successfully connected to the DataBase Server...");
}
Statement statement;
statement = con.createStatement();
String selectQuery = "SELECT idSubTask, startDate, endDate FROM tasks where idTask like 'T3' ";
ResultSet resultSet = null;
resultSet = statement.executeQuery(selectQuery);
if (resultSet != null) // Success
{
while (resultSet.next()) {
String idSubTask = (String) resultSet.getObject("idSubTask ");
String startDate= (String) resultSet.getObject("startDate");
String endDate = (String) resultSet.getObject("endDate ");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
Date dateS = sdf2.parse(dataInicio);
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
Date dateF = sdf3.parse(dataFim);
//DELETE
System.out.println("" + idSubTask + " " + startDate+ " " + endDate);
TaskSeries schedule1 = new TaskSeries("Scheduled Tasks");
schedule1.add(new Task(idSubTask,
new SimpleTimePeriod(dateS, dateE)));
collection.add(schedule1);
}
}
resultSet.close();
} catch (Exception e) {
System.out.println("" + e);
}
IntervalCategoryDataset dataset = collection;
JFreeChart chart = ChartFactory.createGanttChart(
"Gantt Chart Example", // chart Heading
"SubTask", // X-axis label
"Date", // Y-axis label
dataset, // dataset
true, // legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(new Color(0xff, 0xff, 0xcc));
ChartFrame frame = new ChartFrame("Gantt Chart", chart);
frame.setVisible(true);
frame.setSize(400, 350);
}
}
非常感謝主席先生,你救我一命:) – rpirez