1

I am using MilliDTSC class in my program. I want the refresh rate to be set as 100ms . I have used javax.swing.Timer to update the GUI after 100ms, but my domain axis updates after each millisecond, because unit is 'MilliSecond' (as shown below) ScreenShot

Is there any way to change the unit of domain axis to 100ms instead of 1ms ?

Gagan93
  • 1,826
  • 2
  • 25
  • 38
  • 1
    Try `axis.setDateFormatOverride()`, seen [here](http://stackoverflow.com/a/22264230/230513). – trashgod Apr 11 '14 at 23:21
  • I could not get it, can you explain in a better way as per my code It is posted here http://pastebin.com/2FbtDWme – Gagan93 Apr 12 '14 at 04:28

2 Answers2

1

Try this code :

ValueAxis range = plot.getRangeAxis();
range.setRange(0, 1000);
domain.setTickUnit(new NumberTickUnit(100));

and please put false in autorange like this :

domain.setAutoRange(false);

Edited:

Please Replace:

XYPlot plot = chart.getXYPlot();
final ValueAxis domain = plot.getDomainAxis();

domain.setAutoRange(true);


NumberAxis axis = new NumberAxis();
axis.setTickUnit(new NumberTickUnit(100));

ValueAxis range = plot.getRangeAxis();
range.setRange(0, 100);

with :

XYPlot plot = chart.getXYPlot();
final NumberAxis domain = (NumberAxis)plot.getDomainAxis();

domain.setAutoRange(false);

domain.setRange(0,1000);
domain.setTickUnit(new NumberTickUnit(100));

NumberAxis range = (NumberAxis)plot.getRangeAxis(); 
range.setRange(0,100);
Raju Sharma
  • 2,496
  • 3
  • 23
  • 41
  • timeAxis is the reference of which Class ? Please explain a bit more, I dont know much about this library – Gagan93 Apr 12 '14 at 04:18
  • 1
    What your Time(ms) axis object is that is represented by me here as timeAxis – Raju Sharma Apr 12 '14 at 04:23
  • I have posted code here, http://pastebin.com/2FbtDWme Now tell me whre should I do it – Gagan93 Apr 12 '14 at 04:24
  • setTickUnit is not defined for 'domain' type (eclipse shows an error) – Gagan93 Apr 12 '14 at 04:52
  • and why are you editing the range axis, I need to edit only domain axis – Gagan93 Apr 12 '14 at 04:59
  • thanks brother for sparing your valuable time and helping me, but eclipse is giving a class cast exception when we try to cast to NumberAxis " java.lang.ClassCastException: org.jfree.c hart.axis.DateAxis cannot be cast to org.jfree.chart.axis.NumberAxis " – Gagan93 Apr 12 '14 at 05:36
  • 1
    so please try to replace NumberAxis to DateAxis for domain only and best of luck. – Raju Sharma Apr 12 '14 at 05:39
1

Found the answer:

No need to use any methods, they will give one or another exception, see this answer, here. You will have to create one class, MultipleOfMillisecond. After that, you can customize the time period according to your choice, as per argument passed to constructor of MultipleOfMillisecond.

Community
  • 1
  • 1
Gagan93
  • 1,826
  • 2
  • 25
  • 38