Change size of legend items for large charts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
blaskowski94
Posts: 2
Joined: Mon Jun 26, 2017 3:26 pm
antibot: No, of course not.

Change size of legend items for large charts

Post by blaskowski94 » Fri Jul 07, 2017 9:41 pm

I am trying to make the charts I draw dynamically adjust based on the size (width & height) of chart requested. I am having trouble getting the legend to cooperate. I can change the legend font size just fine, but I cannot figure out how to increase the size of the markers next to the legend labels. For example, if I have a green bar, the legend has a green box next to the label "bar 1". When the charts get very large (5000px x 5000px +), the green box is impossible to see. Is there any way to increase its size?

For context I am having this problem with bar, scatter and line charts. I am using CategoryRenderer for the bar chart and XYItemRenderer for the line and scatter. I have implemented my own ChartTheme where I set all the different properties. If it would be helpful I can post the code for that.

Thanks,
-Bob

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Change size of legend items for large charts

Post by paradoxoff » Wed Jul 12, 2017 12:02 pm

You can manually set the legend shape by either calling setLegendShape(int series, Shape theShape) or setBaseLegendShape(Shape theShape). Note that the latter will only have an effect for series where lookupLegendShape(int series) returns null.

blaskowski94
Posts: 2
Joined: Mon Jun 26, 2017 3:26 pm
antibot: No, of course not.

Re: Change size of legend items for large charts

Post by blaskowski94 » Wed Jul 12, 2017 3:56 pm

Thank you for your reply. This works well for bar charts and I have solved my problem for scatter plots by manually setting the series shape and size. However, I'm still having issues with line charts. In my line charts, I use solid, dashed and dotted lines. When the chart becomes very large and the line width has to increase as well, all that's shown in the legend are square blocks. Is there a way to still make them appear dashed and dotted?

Edit: I found the solution to this in the XYLineAndShapeRenderer class by using the setLegendLine method. Thank you again for your help and I hope this helps someone else.

Locked