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:
I would like to have a square pattern of these colors. Here is an example
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