1

I'm making a program that deals with a large collection of 2D data. I'm displaying this data in an XYPlot. Is there some way I can mark which direction the line is moving over time? The data bounces all over the plot, but needs to be in a specific order, so a scatter plot won't work for me.

EDIT: To clarify - Neither the X or Y axis is time. This is a parametric plot.

Inglonias
  • 468
  • 1
  • 5
  • 18

1 Answers1

2

I have discovered a possible solution. It needs some working through to make it look right, but it works for now.

There is a class in JFreeChart called XYPointerAnnotation, which allows you to add arrows to your chart of a custom angle, length, and width. I'm still trying to figure the class out, but so far it seems to do well enough for my purposes. Code attached:

for (int i = 0;i < data.getItemCount(0) - 1;i++)
    {
    double x1 = data.getSeries(0).getDataItem(i).getXValue();
    double x2 = data.getSeries(0).getDataItem(i + 1).getXValue();

    double y1 = data.getSeries(0).getDataItem(i).getYValue();
    double y2 = data.getSeries(0).getDataItem(i + 1).getYValue();

    double angle = Math.atan2(y1 - y2, x2 - x1) + Math.PI;
    XYPointerAnnotation arrow = new XYPointerAnnotation("",x1,y1,angle);

    if (i == 0)
        {
        arrow.setText("Start");
        }
    else if (i % 5 == 0)
        {
        arrow.setText(Integer.toString(i));
        }

    arrow.setLabelOffset(15.0);
    arrow.setToolTipText(Integer.toString(i));
    _originalPlot.addAnnotation(arrow);
    }
Inglonias
  • 468
  • 1
  • 5
  • 18