1

System.out.println("Hello all that use Java && JFreeChart!");

I am writing an application that allows cyclists, such as myself, to keep track of their average speed, distance, and time for a given trip. They are to enter that data, and then a JFrame pops up with their graphed information. I have a class that converts the elapsedTime to a String format (for display purposes!), but I don't think JFreeChart can take it in for a Range value. In fact, I checked out their API documentation, http://www.jfree.org/jfreechart/api/javadoc/index.html , and quickly found out that Range() only takes parameters of type double! Not String, not Time, double. This is a letdown because I intended to set the interval of graph displayed equal to the interval formed by their minimum time and maximum time. Is there any way around this?

Mike Warren
  • 3,796
  • 5
  • 47
  • 99

2 Answers2

2

From my understanding of the question, you could try:

double value = Double.parseDouble(string);

However, this will obviously not work if you put in a time-based value. From the comments you have made, perhaps a TimeSeriesChart from ChartFactory could solve your problem.

syb0rg
  • 8,057
  • 9
  • 41
  • 81
  • Time, as double? I don't know how this would work, but it is worth a shot. What kept me from taking that route is, how would "01:31:12" look as double? //I guess, this isn't called computer SCIENCE for nothing! – Mike Warren Apr 20 '13 at 13:23
  • @MikeWarren: you need to better define your problem. Please edit your original question and tell us the necessary details. – Hovercraft Full Of Eels Apr 20 '13 at 13:31
  • I found something that looks like it might work: TimeSeries and TimeSeriesDataItem. Here is the link in case anyone wants to check this out: http://www.jfree.org/jfreechart/api/javadoc/index.html – Mike Warren Apr 20 '13 at 13:32
  • @HovercraftFullOfEels I thought I made it clear! I am trying to display the cyclist's ride times in graphical format (with the record number being the domain and the range being the ride time itself). For motivational purpose, I am making the minimum displayed range value their fastest time and the maximum displayed range value their slowest time. Is this better? – Mike Warren Apr 20 '13 at 13:34
  • 1
    @MikeWarren Take a look at the updated answer. Maybe that could help you solve your problem. – syb0rg Apr 20 '13 at 13:38
  • This is what I use to create the JFreeChart, but yes! Thank you for that post; I could just `createTimeSeriesChart()`! Why didn't I think of this earlier!? – Mike Warren Apr 20 '13 at 13:42
  • and yes, my theory about that TimeSeries being used for the data was right. An example can be found here (if anyone is interested in this themselves): http://www.java2s.com/Code/Java/Chart/JFreeChartTimeSeriesDemo12.htm – Mike Warren Apr 20 '13 at 13:52
  • Now if only there was a way to make it so that the TimeSeries would appear in the y-axis – Mike Warren Apr 20 '13 at 14:08
  • @MikeWarren If you can't find an answer to that on your own, I would ask it as a separate question. – syb0rg Apr 20 '13 at 14:09
0

It seems like the ChartFactory.createTimeSeriesChart() is the way to go, but it is the most disappointing way to go. Sure, you can switch the axes, but this does NOTHING to the data! The smartest way to approach this would be an XYLineChart, and then use a RelativeDateFormat : http://www.jfree.org/jfreechart/api/javadoc/index.html . That way, your range values go in as type long, and then you can just bring in a DateAxis that has RelativeDateFormat. Problem solved.

Mike Warren
  • 3,796
  • 5
  • 47
  • 99
  • 2
    You can write your own variation of the [factory](http://www.jfree.org/jfreechart/api/javadoc/src-html/org/jfree/chart/ChartFactory.html#line.1886) that puts things where you want; post a new question if you get stuck; cite your [cross-post](http://www.jfree.org/forum/viewtopic.php?f=3&t=116463). – trashgod Apr 23 '13 at 17:34