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.
Asked
Active
Viewed 499 times
1 Answers
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);
-
Thanks for your response,will try it.But is the index of a data series API specific,or is it just the index.How should I be implementing that. – Madusudanan Dec 26 '11 at 14:26
-
I've updated the example to skip every other `Shape`, irrespective of series. – trashgod Dec 27 '11 at 10:57
-
1Thanks for your implementation example.I achieved it.Thanks much for your help. – Madusudanan Dec 27 '11 at 11:07