How to omit fraction in seconds at JFreeChart?
Asked Answered
C

4

1

Friends, Atlast i just generate JFreeChart for the collected value from the database. But on that, i just use

Second sec = new Second();
Series.add(sec.previous(), ExistingValue);
Series.add(sec, Value);
Dataset = new TimeSeriesCollection(Series);

But it displayed result contains additional fractional point. And it just incremented with 0.250 seconds. Actually i want seconds only incremented with 1. How can i get it? And Is there any way to start Y angle chart from given value other than 0?

enter image description here

Clerestory answered 21/1, 2014 at 9:17 Comment(0)
S
2

You can get a reference to the Domain axis (x-axis) of your plot/chart and set a SimpleDateFormat of any format you like:

JFreeChart chart;
DateAxis axis  = (DateAxis)chart.getXYPlot().getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

The same can be done to format the Range axis (y-axis).

Selfimportant answered 21/1, 2014 at 10:50 Comment(1)
You have to be careful when overriding the tick label format, because it won't necessarily change the tick spacing (just the label) and you might end up with duplicate labels (e.g. if the spacing is 1/4 second and you format the labels to show seconds only, then you will could get "14:23:39" appearing four times).Annettannetta
I
2

Here i used the following code works good.

TimeSeries series1 = new TimeSeries("Random Data", Minute.class);

series1.add(new Minute(mi,hr,dat,mo,yr), value );
Iridize answered 21/1, 2014 at 9:45 Comment(0)
S
2

You can get a reference to the Domain axis (x-axis) of your plot/chart and set a SimpleDateFormat of any format you like:

JFreeChart chart;
DateAxis axis  = (DateAxis)chart.getXYPlot().getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

The same can be done to format the Range axis (y-axis).

Selfimportant answered 21/1, 2014 at 10:50 Comment(1)
You have to be careful when overriding the tick label format, because it won't necessarily change the tick spacing (just the label) and you might end up with duplicate labels (e.g. if the spacing is 1/4 second and you format the labels to show seconds only, then you will could get "14:23:39" appearing four times).Annettannetta
A
2

In the DateAxis constructor, you will find this piece of code that constructs the set of "standard" tick sizes for a DateAxis:

DateAxis.createStandardDateTickUnits(zone, locale)

When rendering the axis, JFreeChart will choose the smallest tick size that doesn't cause the labels to overlap. At any time you can change the set of standard sizes that JFreeChart chooses from, just call setStandardTickUnits(...) and supply your own set.

Or, you can switch off the automatic tick unit selection and just set a fixed tick size using the setDateTickUnit() method, but now it is your responsibility to choose a tick size that doesn't result in overlapping labels.

Annettannetta answered 22/1, 2014 at 8:32 Comment(1)
please look in to this question #42224895Vastah
C
1

Actually i use the folloeing code to solve my problem. that is,

        DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
        DateAxis axis = (DateAxis) Plot.getDomainAxis();
        axis.setDateFormatOverride(formatter);

It displays time like 01:15:45AM

Clerestory answered 29/1, 2014 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.