TimeSeriesChart with tick hh:mm mm:dd:yy

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Peter

TimeSeriesChart with tick hh:mm mm:dd:yy

Post by Peter » Thu Jul 18, 2002 12:26 am

I want to generate a graph with horizantal axis has tick label in hh:mm mm/dd/yy format. I try to use BasicTimeSeries and createTimeSeriesChart. The graph just maked the horizatal axis with hh:mm like 19:02 19:10 ....

Am I doing something wrong?

Part of the code as below,


BasicTimeSeries series1 = new BasicTimeSeries("Test1", "Millisecond", "Value", FixedMillisecond.class);
Date now = new Date();
try {
series1.add(new FixedMillisecond(now.getTime()), new Double(50.1));
....
TimeSeriesCollection data = new TimeSeriesCollection();
data.addSeries(series1);
JFreeChart chart = ChartFactory.createTimeSeriesChart("IP Performace Report", "Time", "Kbps", data, true);


Your help is greatly appreciated.

Peter

reji

Re: TimeSeriesChart with tick hh:mm mm:dd:yy

Post by reji » Thu Jul 18, 2002 9:39 am

Hi,

Check this,
-----------------------------------------------------
XYPlot plot = (XYPlot)chart.getPlot();

HorizontalDateAxis ax = (HorizontalDateAxis)plt.getDomainAxis();

ax.setAutoTickUnitSelection(false);

ax.setTickUnit(new DateUnit(Calendar.SECOND, 1));

ax.getTickLabelFormatter().applyPattern(" MM/dd/yy HH:mm");

-----------------------------------------------------

regards,

reji

Peter

Re: TimeSeriesChart with tick hh:mm mm:dd:yy

Post by Peter » Thu Jul 18, 2002 5:20 pm

Reji,

It works! Thank you so much!

The problem now is that th tick label is too long. For the last tick very close to the right boundary of chart, the label is cut off. Something like this

| (left boundary) ................ (right boundary) |
02/26/02 19:

Is it possible to control this thing or make the label printed out in two line, such as

02/26/02
19:30

Thanks a lot for you help,
Peter

reji

Re: TimeSeriesChart with tick hh:mm mm:dd:yy

Post by reji » Fri Jul 19, 2002 1:41 am

Peter,

You can plot the labels in vertical format..

try this
----------------------------------------------------
XYPlot plot = chart.getXYPlot();

HorizontalDateAxis axis = (HorizontalDateAxis)plot.getDomainAxis();

axis.setVerticalTickLabels(true);

----------------------------------------------------

Regards,

Reji

reji

Re: TimeSeriesChart with tick hh:mm mm:dd:yy

Post by reji » Fri Jul 19, 2002 2:12 am

Peter,

I haven't tried to print horizontal axis labels in multi-lines. Lets hope somebody else will answer this problem..

regards,

Reji

Locked