jfreechart为我的图例项目形状添加边框

时间:2018-06-01 11:59:14

标签: java jfreechart

我想为我的图例项目形状添加边框。没有到legendTitle但只有legendItem形状。这是代码的一部分

LegendItemCollection chartLegend = new LegendItemCollection();
Shape legendShape = new Rectangle(10, 10);
LegendItem legendItem = new LegendItem("Text", some color);
legendItem.setLabelFont(new Font(ARIAL_FONT, Font.PLAIN, 8));
legendItem.setShape(legendShape);
chartLegend.add(legendItem);
plot.setFixedLegendItems(chartLegend);

GridArrangement grid = new GridArrangement(3, 1);

LegendTitle legendTitle = new LegendTitle(plot, grid, grid);
legendTitle.setBackgroundPaint(Color.WHITE);
legendTitle.setPosition(RectangleEdge.BOTTOM);
legendTitle.setItemLabelPadding(new RectangleInsets(0, 1, 0, 5));
legendTitle.setPadding(new RectangleInsets(0, 15, 0, 0));
chart.addLegend(legendTitle);

1 个答案:

答案 0 :(得分:1)

我用这3行代码解决了它

legendItem.setLineVisible(true);
legendItem.setLinePaint(Color.BLACK);
legendItem.setLineStroke(new BasicStroke(0.1f));