how to specify the unit range on x-axis and y-axis
how to specify the unit range on x-axis and y-axis
I am constructing a line chart. i want the unit range on x-axis and y-axis as 10. how to specify the unit range. I am using XYDataSet. The range is taking automatically, how to specify this unit range explicitly.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
You can use the setTickUnit() method to specify the gap between tick marks/labels, and the setRange() method to specify the overall range for the axis.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


how can i set the interval of x-axis
thax for ur replaying,
but i didnt get what u sent.
my problem is in x-axis the labels are coming like(0,25,50,75,100,125...) so the difference between adjacent points are 25 . but i want to make it as 15 only. so that i can get the report like(0,15,30,45,60,75..etc)..
please send me the code how i have to use this
but i didnt get what u sent.
my problem is in x-axis the labels are coming like(0,25,50,75,100,125...) so the difference between adjacent points are 25 . but i want to make it as 15 only. so that i can get the report like(0,15,30,45,60,75..etc)..
please send me the code how i have to use this
-
- Posts: 18
- Joined: Thu May 11, 2006 11:22 pm
Do decimal ticks work?
I have data like (UnixTimestamp long, value float) such as (1155081441000, 1.2794) and (1155081441000, 1.2797). They are two series at a time on Aug 8, 2006, so I want to plot 1 curve with a value at 1.2794 and another curve with a value at 1.2797.
When I plot it, it appears to autoscale and label the y values as:
1.27970
1.27965
1.27960
1.27955
1.27950
1.27945
1.27940
I would like:
1.2797
1.2796
1.2795
1.2794
From this present thread and thread# 19188 (as a new user I cannot add a URL)
I add the following code between the example I found to get and set the tick unit:
plot.setRangeCrosshairVisible(true);//Some example I found. My added code below.
double myUnit;// = 0.0001;
NumberAxis range = (NumberAxis)plot.getRangeAxis();
//range.setTickUnit(new NumberTickUnit(myUnit));
NumberTickUnit ntu = range.getTickUnit();
myUnit = ntu.getSize();
System.out.println("ntu=" + myUnit);
XYItemRenderer r = plot.getRenderer();//Some example I found. My added code above.
With the commented out lines as above (trying to GET the current tick unit), I get 1.0 as the tick unit. Which I would have expected to be 0.00005 when it autoscales. I tried this code before and after the rendering and they are both the same values.
With the lines not commented out (trying to explicitly SET the tick unit). I get 1.0E-4 as the tick unit which is what I set 0.0001. But the rendering is listed like:
1.28
1.28
1.28
1.279
Is this a bug? Or how should I set the tick unit for 0.0001 intervals?
When I plot it, it appears to autoscale and label the y values as:
1.27970
1.27965
1.27960
1.27955
1.27950
1.27945
1.27940
I would like:
1.2797
1.2796
1.2795
1.2794
From this present thread and thread# 19188 (as a new user I cannot add a URL)
I add the following code between the example I found to get and set the tick unit:
plot.setRangeCrosshairVisible(true);//Some example I found. My added code below.
double myUnit;// = 0.0001;
NumberAxis range = (NumberAxis)plot.getRangeAxis();
//range.setTickUnit(new NumberTickUnit(myUnit));
NumberTickUnit ntu = range.getTickUnit();
myUnit = ntu.getSize();
System.out.println("ntu=" + myUnit);
XYItemRenderer r = plot.getRenderer();//Some example I found. My added code above.
With the commented out lines as above (trying to GET the current tick unit), I get 1.0 as the tick unit. Which I would have expected to be 0.00005 when it autoscales. I tried this code before and after the rendering and they are both the same values.
With the lines not commented out (trying to explicitly SET the tick unit). I get 1.0E-4 as the tick unit which is what I set 0.0001. But the rendering is listed like:
1.28
1.28
1.28
1.279
Is this a bug? Or how should I set the tick unit for 0.0001 intervals?
Have you tried something like this yet?
Code: Select all
TickUnits units = new TickUnits();
DecimalFormat fmt = new DecimalFormat("0.0001");
units.add(new NumberTickUnit(0.0001, fmt));
units.add(new NumberTickUnit(0.0002, fmt));
units.add(new NumberTickUnit(0.0005, fmt));
//
// etc
//
axis.setStandardTickUnits(units);
No, I did not try anything like that, skunk. With your code, the chart is being rendered with 4 decimal places, so I guess this is a step in the right direction. Although I get:
1.2801
1.2801
1.2801
1.2791
which I need to be 1.2794 through 1.2797.
I wanted to say this appears to be a sweet solution from the skunk, but I have 2 questions.
I am storing my data in a MySQL database as a float and when I retreive it, it is still 4 decimals as I would expect as a Java float. So my problem seems to be when I try to give org.jfree.data.time.TimeSeries.add a double or java.lang.Double which extends java.lang.Number using one of these methods:
add(RegularTimePeriod period, double value) or
add(RegularTimePeriod period, java.lang.Number value)
1) How do I add my float to the TimeSeries?
Even when I explicitly set:
double d = 1.2794;
and print d, I get 1.2794 printed instead of say 1.2793999910354614 which I would get if I use:
double d = myFloat;//myFloat = 1.2794 and prints d as 1.2793999910354614. Either way, I still get the labels:
1.2801
1.2801
1.2801
1.2791
in the chart.
And it's not like it's labeled 1.2801 and my data point is below that line either. The data point is on the top 1.2801 line and the second series' data point is on the 1.2791 line (which should be 1.2794). Although "the line" is labeled thrice on the axis as 1.2801. Nice.
2) Why the multiple calls to units.add?
Should I make 1 call for each series added? And in my case always using 0.0001?
1.2801
1.2801
1.2801
1.2791
which I need to be 1.2794 through 1.2797.
I wanted to say this appears to be a sweet solution from the skunk, but I have 2 questions.
I am storing my data in a MySQL database as a float and when I retreive it, it is still 4 decimals as I would expect as a Java float. So my problem seems to be when I try to give org.jfree.data.time.TimeSeries.add a double or java.lang.Double which extends java.lang.Number using one of these methods:
add(RegularTimePeriod period, double value) or
add(RegularTimePeriod period, java.lang.Number value)
1) How do I add my float to the TimeSeries?
Even when I explicitly set:
double d = 1.2794;
and print d, I get 1.2794 printed instead of say 1.2793999910354614 which I would get if I use:
double d = myFloat;//myFloat = 1.2794 and prints d as 1.2793999910354614. Either way, I still get the labels:
1.2801
1.2801
1.2801
1.2791
in the chart.
And it's not like it's labeled 1.2801 and my data point is below that line either. The data point is on the top 1.2801 line and the second series' data point is on the 1.2791 line (which should be 1.2794). Although "the line" is labeled thrice on the axis as 1.2801. Nice.
2) Why the multiple calls to units.add?
Should I make 1 call for each series added? And in my case always using 0.0001?
Part of your problem is basic computer science. The major issue is the IEEE format for floating point. 0.1f cannot be exactly represented as a floating point number. 0.1f != 0.1d. The float literal 0.1f is equal to the double value 0.10000000149011612. This problem makes itself most obvious when multiplying a floating point number by a large literal, thus shifting the error.
Yes, I found something on the float/double issue before I posted, but when I explicitly set double d = 1.2794; and print d, I get 1.2794.
I changed my database to use double instead of float (which seems like a waste) and I do recall using double and almost never using float in programming. I thought I was gaining precision instead of luckily avoiding an IEEE oddity.
So what's with the labels and question 2?
I have values
1.2797
1.2796
1.2795
1.2796
1.2795
1.2796
1.2795
and the labels all say 1.2801 (3 times) yet the chart does follow the actual data. It is just the labels which are wrong.
I changed my database to use double instead of float (which seems like a waste) and I do recall using double and almost never using float in programming. I thought I was gaining precision instead of luckily avoiding an IEEE oddity.
So what's with the labels and question 2?
I have values
1.2797
1.2796
1.2795
1.2796
1.2795
1.2796
1.2795
and the labels all say 1.2801 (3 times) yet the chart does follow the actual data. It is just the labels which are wrong.