Set Legend Stroke of Line Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rjcarr
Posts: 2
Joined: Thu May 15, 2008 10:21 pm

Set Legend Stroke of Line Chart

Post by rjcarr » Thu May 15, 2008 10:26 pm

I tried searching for this as it seems like it would be asked, but I couldn't find anything. Sorry if this is a duplicated.

I have a Line Chart, without shapes, and I'd like the stroke of the lines in the chart to be 1. The (default) lines in the legend, however, also have a stroke of 1, but they are hard to see. I'd like to increase the stroke size of *just* the legend.

As a fix I've created a shape to replace the line legend (similar to what is done in LineChartDemo4) but I can't figure out how to get it filled. Here's the code (from the demo) on how that was done:

Code: Select all

XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)plot.getRenderer();
renderer.setLegendLine(new Rectangle2D.Double(-4.0, -3.0, 8.0, 6.0));
So, either increasing the stroke of the legend line or creating a filled shape would work. Any ideas?

rjcarr
Posts: 2
Joined: Thu May 15, 2008 10:21 pm

Post by rjcarr » Thu Jun 05, 2008 1:34 am

Bumping my own question here. Can somebody just give me a response saying my question seems possible or impossible?

Thanks!

Alphonse87
Posts: 9
Joined: Thu May 08, 2008 3:18 pm

Post by Alphonse87 » Wed Jun 11, 2008 4:47 pm

Hi !

I don't know if my solution will help you, but I did something which could interest you : I created a kind of "StrokeGifCeator" : it returns a GIF with the stroke you want.

Code: Select all

public class StrokeGifCreator {
	private BufferedImage image;

	public Image createGif(final Stroke stroke) {
		return createGif(stroke, 70, 16);
	}

	public Image createGif(final Stroke stroke, final int width, final int height) {
		image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

		final Graphics2D gc = (Graphics2D) image.getGraphics();
		gc.setPaint(Color.white);
		final Rectangle2D rectangle = new Rectangle2D.Double(0, 0, width, height);
		gc.fill(rectangle);
		gc.setColor(Color.black);
		gc.setStroke(stroke);
		gc.drawLine(0, height / 2, width, height / 2);
		gc.dispose();

		return image;
	}
}
So You could disable the legend of the chart and create your own with those Images.

Hope it will help :)

Locked