JFreechart Making Time Servers ticked

I have time series of data that I would like to build on the tick scale, and not in the time scale.

eg. If the series contains points obtained at times: 10, 15, 30, 100. Instead of superimposing them on the regular axis of the time series, where the distance between 30 and 100 points is equal to 70, I would like the distance between each of these indicates 1 unit . Essentially, I want to build points in the index of points in the underlying dataset.

Is this easy to do in JFreechart.

I had time to implement my own timeline, but it got confused. I would also like the labels to display the time, not the tick number.

+4
source share
2 answers

I donโ€™t know how to create a chart with data elements that have a time coordinate, and then ignore the time it was created, but when you create TimePeriodValues, you can lie about the TimePeriod presented by the data to convince JFreechart that they are regularly spaced. Of course, this means that you have to manually pre-process the data for sorting in order to sequentially count events (if you do not already have event numbers associated with the series?)

I donโ€™t know how to display anything other than the x coordinate on the axis, but you can display a label next to each data point. (The demo of Annotation in the demo collection shows how.)

+3
source

I handled the same thing using NumericAxis instead of DateAxis, and then overriding the refreshTicksHorizontal method to create a list of NumericTicks, but with a label formatted as dates. It was a little hack, but I did the work for me.

NumberAxis domainAxis = new NumberAxis("Date") { @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { List ticks = new ArrayList(); //you'll need to have corresponding date objects around //or know how to match them up on the graph for (int i = 0; i < dates.size(); i++) { String label = dateFormat.format(dates.get(i)); NumberTick tick = new NumberTick(i, label, TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0); ticks.add(tick); } return ticks; } }; 
+1
source

All Articles