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

A.Mohamed Bilal
  • 115
  • 1
  • 13

4 Answers4

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 );
AmirtharajCVijay
  • 1,078
  • 11
  • 12
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).

Heisenberg
  • 56
  • 4
  • 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). – David Gilbert Jan 22 '14 at 08:35
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.

David Gilbert
  • 4,427
  • 14
  • 22
  • please look in to this question http://stackoverflow.com/questions/42224395/real-time-on-x-axis-with-adjustable-scale-on-x-axis – JAVA Feb 14 '17 at 12:30
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

A.Mohamed Bilal
  • 115
  • 1
  • 13