通过向{JFreeChart构造函数传递XYSeriesCollection
数据集创建折线图后,我试图获得系列Stroke
/ Paint
/ Shape
:
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)chart.getXYPlot().getRenderer();
for (int i = 0; i < dataset.getSeriesCount(); i++) {
renderer.getSeriesStroke(i);
renderer.getSeriesPaint(i);
renderer.getSeriesShape(i);
}
但都返回null。
为什么?如何获取非null对象?
答案 0 :(得分:2)
XYLineAndShapeRenderer
是XYItemRenderer
,支持“在XYPlot
上呈现单个(x,y)项目的直观表示”。虽然相应的系列属性为null
,但可以访问项属性。从此example开始,以下更改将生成显示的输出:
代码:
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)chart.getXYPlot().getRenderer();
for (int i = 0; i < xyPlot.getDataset().getSeriesCount(); i++) {
System.out.println(renderer.getItemStroke(i, 0));
System.out.println(renderer.getItemPaint(i, 0));
System.out.println(renderer.getItemShape(i, 0));
System.out.println(renderer.getItemShape(i, N));
}
控制台:
$ java -cp .:$JFREE_LIB/* ScatterShape
java.awt.BasicStroke@d1a007c0
java.awt.Color[r=255,g=85,b=85]
java.awt.geom.Rectangle2D$Double[x=-3.0,y=-3.0,w=6.0,h=6.0]
java.awt.geom.GeneralPath@7ef51f0f