Can someone tell me how to change the color swatches of a series in a legend in jfreechart. Now I have a small series color string, for example:
![Example](https://fooobar.com//img/8f9d8fe671df4ef24df04166aa85e901.png)
I would like to have a square pattern of these colors. Here is an example
![Example](https://fooobar.com//img/6b91a2a7cef1073a3baebf13e6ec47bc.png)
Can someone help me?
Ok, I found a solution. At least I think. Of course, there is no easy way to do this. Now you know the setShape (square) method that will do the trick, at least I did not find it.
Basically, the XY chart and timeline have a "line style" legend by default, unlike a histogram, for example (if it has a square legend by default). So I had to delete the current legend and create a new one with square color swatches, and this new legend will add my timeline.
LegendItemCollection legend = new LegendItemCollection(); for (int i = 0; i < seriecCount; ++i) { chart.getXYPlot().getRenderer().setSeriesPaint(i, colorPalette.get(i)); LegendItem li = new LegendItem(data.getSeriesName(i), "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX, colorPalette.get(i)); legend.add(li); } chart.getXYPlot().setFixedLegendItems(legend);
Thank you for attention. Hope this helps someone.
Darek source share