I have got myself into a bit of a pickle, my charts allows users to select as many categories as they wish to the point that the chart image is taken up with just the legend.
So I have used the get legend function and put this into and chart image giving the users the ability to see the chart and the legend seperatly.
The problem I am having is with my second chart all i want to see is the legend I am adding to it. So I really would like to remove the plot is possible. Was thinking something along the lines of setting the size of the legendbox or making the plot transparent.
Any ideas?
Exctracting and showing only Legend
-
- Posts: 5
- Joined: Wed Nov 15, 2006 5:03 pm
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
You could use the LegendTitle's draw() method to draw the legend to any Graphics2D instance. So you could easily create a JPanel subclass that displays just a LegendTitle.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 7
- Joined: Wed May 17, 2006 12:46 pm
-
- Posts: 13
- Joined: Mon Aug 14, 2006 9:14 pm
There's another way to do it that I am currently working on:
Create a new implementation of the Plot class that does nothing in the draw methods (I didn't include the code).
This will obviously prevent the plot from being drawn.
Creating the Legend Only chart is then very straightforward:
Obviously you can set many more properties, but this is the basic concept I am using.
I decided to take this route instead of the JPanel approach, because I wanted to treat a Legend Only chart just like any other.
Create a new implementation of the Plot class that does nothing in the draw methods (I didn't include the code).
This will obviously prevent the plot from being drawn.
Creating the Legend Only chart is then very straightforward:
Code: Select all
JFreeChart legendChart = new JFreeChart("", null,
new HiddenPlot(),
false); //Hidden plot is a plot implementation that does not draw anything.
LegendTitle legendTitle = new LegendTitle(<CHART_WITH_DATA>.getPlot(),
new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0),
new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 0));
legendChart.addLegend(legendTitle);
I decided to take this route instead of the JPanel approach, because I wanted to treat a Legend Only chart just like any other.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I generally dislike "workarounds", but that one is quite clever.hookumsnivy wrote:I decided to take this route instead of the JPanel approach, because I wanted to treat a Legend Only chart just like any other.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

