HH:MM in Y axis Barchart Plotting

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
harishkar
Posts: 2
Joined: Fri Sep 04, 2015 1:46 pm
antibot: No, of course not.

HH:MM in Y axis Barchart Plotting

Post by harishkar » Fri Sep 04, 2015 2:02 pm

Hi
I need to plot barchart some Machine names - xaxis (String) against hours minutes which will be in format HH:MM in Y axis. Each Machine will have 2 time values . eg Machine 1 will have 09:22 and 01:11, so 2 bars will be required in 1 machine.
The time series is not useful as I am not plotting against any date . The exisitng defaultdata set is taking only int or double as input . Is there any way to mention HH:MM as input.
I am trying different features in API but not able achive my requirement and any hint / help will be of great help.

Thanks,
harishkar

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: HH:MM in Y axis Barchart Plotting

Post by John Matthews » Fri Sep 04, 2015 6:27 pm

Given a CategoryPlot, you can substitute a DateAxis for the factory's default ValueAxis and use a suitable DateFormat. You'll need to scale your data to represent milliseconds.

Code: Select all

DateAxis range = new DateAxis("HH:mm");
SimpleDateFormat f = new SimpleDateFormat("HH:mm");
f.setTimeZone(TimeZone.getTimeZone("GMT"));
range.setDateFormatOverride(f);
plot.setRangeAxis(range);

harishkar
Posts: 2
Joined: Fri Sep 04, 2015 1:46 pm
antibot: No, of course not.

Re: HH:MM in Y axis Barchart Plotting

Post by harishkar » Tue Sep 08, 2015 11:20 am

Thanks John. It does work perfectly as expected and I am able to plot the values successfully .

Also is there anyway we can show the HH:mm value as labels as we doing for numbers like
plot.getRenderer().setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
plot.getRenderer().setBaseItemLabelsVisible(true);

Thanks,
Harishkar

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: HH:MM in Y axis Barchart Plotting

Post by paradoxoff » Tue Sep 08, 2015 6:29 pm

In the constructor of StandardCategoryItemLabelGenerator(), you can supply a custom DateFormat.

Locked