Too small candle width with Monthly Timeline

Discussion about JFreeChart related to stockmarket charts.
Locked
Denis Ballant

Too small candle width with Monthly Timeline

Post by Denis Ballant » Fri Feb 20, 2004 10:57 am

Hi there,

I created a monthly timeline (see code below) that includes the 1st day of each month, and excludes all other days. But if I use it to create a DateAxis which is used for a candle stick chart, the candle width is only 1 pixel or so. To go around this problem I had to copy the CandlestickRenderer class and modify it to remove use of maxCandleWidth which was set to unreasonably small values.

Can someone help me resolve this problem or identify the bug in JFreeChart 0.9.16 or in my monthly timeline class below ?

Thanks.

Denis

Code: Select all

public class MonthlyTimeline implements Timeline {
  private Calendar cal = new GregorianCalendar();
  private int day_of_month = 1;   // map all other days of the month on this one

  public long toTimelineValue(long millisecond) {
    cal.clear();
    cal.setTimeInMillis(millisecond);
    cal.set(Calendar.DAY_OF_MONTH, day_of_month);
    return cal.getTimeInMillis();
  }

  public long toTimelineValue(Date date) {
    return toTimelineValue(date.getTime());
  }

  public long toMillisecond(long timelineValue) {
    return timelineValue;
  }

  private boolean sameDay(long time1, long time2) {
    cal.clear();
    cal.setTimeInMillis(time1);
    int year = cal.get(Calendar.YEAR);
    int day = cal.get(Calendar.DAY_OF_YEAR);
    cal.setTimeInMillis(time2);
    return (cal.get(Calendar.YEAR) == year
      && cal.get(Calendar.DAY_OF_YEAR) == day);
  }

  public boolean containsDomainValue(long millisecond) {
    long mapOn = toMillisecond(toTimelineValue(millisecond));

    return sameDay(millisecond, mapOn);
  }

  public boolean containsDomainValue(Date date) {
    return containsDomainValue(date.getTime());
  }

  public boolean containsDomainRange(long fromMillisecond, long toMillisecond) {
    return containsDomainValue(fromMillisecond) && sameDay(fromMillisecond, toMillisecond);
  }

  public boolean containsDomainRange(Date fromDate, Date toDate) {
    return containsDomainRange(fromDate.getTime(), toDate.getTime());
  }
}

Locked