1

I am using jfree chart for graphically displaying metrics.Now I am working on a solution which randomizes graph elements in an XY line chart so that the graph looks smoother.The problem is I dont want the random elements to get the same thickness as the real values,in fact I dont wan't any thickness associated with them.Is there a way to selectively specify point thickness.I am currently using XYLineAndShapeRenderer to render the point thickness.

Madusudanan
  • 1,017
  • 1
  • 15
  • 36

1 Answers1

4

You can override getItemShapeVisible() and arrange for it to return false for the spurious points. You can store the extra information required for the decision in your data model using an implementation of XYZDataset.

As an alternative, consider smoothing the data before rendering it. Such filters typically result in fewer points, which simplifies rendering.

In either case, avoid confusing or misleading changes to the data. A TextTitle, shown here, may clarify the result.

Addendum: getItemShapeVisible() tells you what series and item is under consideration. The default implementation simply asks getSeriesShapesVisible(). Here's an outline:

private static class MyRenderer extends XYLineAndShapeRenderer {

    @Override
    public boolean getItemShapeVisible(int series, int item) {
        System.out.println(series + ":" + item);
        if (item % 2 == 0) return false;
        else return super.getItemShapeVisible(series, item);
    }
}

Addendum: Here's how you might install it:

XYPlot plot = chart.getXYPlot();
MyRenderer renderer = new MyRenderer();
plot.setRenderer(renderer);
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045