3

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?

Mario Boss
  • 1,784
  • 3
  • 20
  • 43
Ada
  • 93
  • 8

1 Answers1

3

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

Koldar
  • 1,317
  • 15
  • 35