1

In Java project, I used JFreeChart 1.0.19 version and XYPlot to draw lines on plot.

I want scale xAxis (Date axis) as date in example - 10:00:05, 10:00:05, 10:00:10, 10:00:15…—scaling for every 5 seconds.

But now when user start with 10:00:03 time, it looks as 10:00:03, 10:00:08, 10:00:13, 10:00:18…

I want that always be scaled of 5 seconds as 10:00:05, 10:00:05, 10:00:10, 10:00:15 and be independently of start time, how to set it?

I configurated domain axis(time axis) as below:

domainAxis.setAutoRange(true);
domainAxis.setAutoTickUnitSelection(true);
domainAxis.setLowerMargin(0.001);
domainAxis.setUpperMargin(0.001);

domainAxis is a object of ValueAxis

My plot looks like as You see the time values are 11:21:57, 11:22:07, 11:22:17 etc. I want that always should be 11:21:55, 11:22:05, 11:22:15 etc.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
ACz
  • 567
  • 5
  • 22
  • 1
    You didn't provide any code, but seems like you'd just check the clock seconds with a `seconds % 5` before doing any recording. – Christopher Schneider Feb 24 '17 at 15:41
  • But what about first four seconds ? There will be no Dates, now is autoscaling – ACz Feb 24 '17 at 15:48
  • Maybe any suggestions how to set it for plot ? – ACz Feb 24 '17 at 15:58
  • 1
    I don't know JFreeChart, otherwise I'd post an answer. I would say you have a few options, though. If possible, don't start until seconds ends in 5. You could also set the scale to `(5 - (n%5))` where `n` is the current second, then set it to 5 after `5-(n%5)` seconds. Third, you can just decide it's not a big deal and go with it :-) – Christopher Schneider Feb 24 '17 at 16:31
  • I've elaborated below. For more specific guidance, please edit your question to include a [mcve] that shows your revised approach. – trashgod Feb 28 '17 at 12:11

1 Answers1

1

Because domainAxis is an instance of DateAxis, you can use setTickUnit() to specify a DateTickUnit having the desired unitType and multiple. In this fragment, the interval is five seconds, and the format includes seconds:

domainAxis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 5));
domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

image

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • `ValueAxis` do not contain method `setTickUnit()` – ACz Mar 01 '17 at 17:28
  • A `DateAxis` _is a_ concrete subclass of the abstract class, `ValueAxis`; your question mentions both, so you might want to check. For more specific guidance, please edit your question to include a [mcve] that shows your revised approach. – trashgod Mar 01 '17 at 20:37