user2474367
user2474367

Reputation: 13

How can i pass a date variable instead of typing dates... in JFreeChart Api

I'm trying to implement Jfreechart API and I am m facing issue:

This is my code

/**Adding data in this series**/
seriesOne.add(new Task("Project Progress Bar",
new SimpleTimePeriod(makeDate(25, Calendar.JUNE, 2013),
makeDate(30, Calendar.JUNE, 2013))));

/**adding second task**/
/**Adding data in this series**/
seriesTwo.add(new Task("Project Progress Bar",
new SimpleTimePeriod(makeDate(28, Calendar.JUNE, 2013),
makeDate(30, Calendar.JUNE, 2013))));

method of makeDate

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;

}

I need to pass as d1="2011-03-06" d2="2011-05-06" d3="2011-05-06" d4="2011-05-06" instead of harcoding the dates how can i do like this below

new SimpleTimePeriod(makeDate(d1),
  makeDate(d2))));

Thanks any help will be appreciated very much Please

Upvotes: 0

Views: 119

Answers (2)

zargarf
zargarf

Reputation: 643

//assuming dates are passed in as a string in the format "yyyy-MM-dd"

public Date makeDate(String date){
return new SimpleDateFormat("yyyy-MM-dd").parse(string);
}

Upvotes: 1

DarthCoder
DarthCoder

Reputation: 354

use DateFormat to get the work done hope this helps ??

Date d=DateFormat.getDateInstance(DateFormat.LONG).parse("June 13, 2013");

Upvotes: 0

Related Questions