Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Personalize legend in jchart2d

I want to personalize the legend in a graph created in JChart2D.

Example

At the moment I can get a legend like the one in the left graph in the image, I want something like the legend in the right graph. Is this possible with JChart2D or I have to use JFreeChart?

like image 911
Ada Avatar asked Dec 20 '25 14:12

Ada


1 Answers

I've looked at JChart2D source code (version 3.2.2) and it seems that it's impossible to generate the legends you're trying to get (both the left and the right ones): this because in JChart2D a legend is a simple string drawn via g.drawString(str,x,y);; hence, there can't be any possible rectangle containing the legend nor images near the strings to improve legend readability.

If you're in a hurry, you might try to change the source code itself by adding a line stroke just before the strings itself. You can do it in Chart2D.paintTraceLabels(Graphics) method, near the end of the method itself, via the method g2d.drawLine(x1,y1,x2,y2);: you can get the stroke via trace.getStroke().

Alternatively, you can contact the main developer to safely perform the needed change. Hope it helps

like image 168
Koldar Avatar answered Dec 22 '25 04:12

Koldar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!