JFree chart selective point thickness

爱⌒轻易说出口 提交于 2019-12-11 13:17:09

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/8635163/jfree-chart-selective-point-thickness

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!