views:

1211

answers:

2

I have a timeseries of data which i'd like to plot on a tick scale rather than a time scale.

e.g. If the series contains points received at times: 10, 15, 30, 100. Instead of plotting these against a regular time series axis where the distance between the 30 and 100 point would be 70, i'd like the distance between each of these points to be 1 unit. Essentially I want to plot the points at the points index in the underlying dataset.

Can this be easily done in JFreechart.

I've had a go at implementing my own Timeline but it's getting messy. I'd also like the labels to reflect the time and not the tick number.

+2  A: 

I don't know of a way to create a chart with data elements that have a time coordinate and then to ignore the times when plotting them, but when you are creating your TimePeriodValues, you can lie about the TimePeriod represented by the data point in order to convince JFreechart that they are regularly spaced. Of course, this means that you'll have to manually pre-process the data to sort it in order to number the events sequentially (unless you already have event numbers associated with the series?)

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

PanCrit
Thanks PanCrit - After playing with Timeline and then with a category plot I reverted back to a time series plot with fake times like you have suggested. I'll take a look at the annotation demo.
pjp
A: 

I handled this same thing by using a NumericAxis instead of a DateAxis and then overriding the refreshTicksHorizontal method to build a list of NumericTicks but with label formatted as dates. It was a bit of a hack, but got the job done 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;
        }
    };
Tony Eichelberger