How can i do like this
final StandardLegend sl = (StandardLegend) chart.getLegend();
sl.setDisplaySeriesShapes(true);
setDisplaySeriesShapes in version 1.0 ?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The charts now use the LegendTitle class to display legends (by default). This class will obtain the legend items from the renderer, and this should return shapes if the renderer is using them. There are some bugs still being shaken out of this code, you might want to try the latest CVS.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Could you pls give an example code?
I have done this.
LegendTitle legendTitle = (LegendTitle) m_chart.getLegend();
And how can I display the shapes on the plot legend in JFreeChart 1.0.10?
-- in 0.9.x it should be:
StandardLegend legend = (StandardLegend) m_chart.getLegend();
legend.setDisplaySeriesShapes(true);
Thanks a lot!
LegendTitle legendTitle = (LegendTitle) m_chart.getLegend();
And how can I display the shapes on the plot legend in JFreeChart 1.0.10?
-- in 0.9.x it should be:
StandardLegend legend = (StandardLegend) m_chart.getLegend();
legend.setDisplaySeriesShapes(true);
Thanks a lot!
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Could you pls give an example code?
If you have configured your renderer to display shapes, they will appear automagically in the legend (unless you are using a custom approach to display the legend).ss wrote:I have done this.
LegendTitle legendTitle = (LegendTitle) m_chart.getLegend();
And how can I display the shapes on the plot legend in JFreeChart 1.0.10?
-- in 0.9.x it should be:
StandardLegend legend = (StandardLegend) m_chart.getLegend();
legend.setDisplaySeriesShapes(true);
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
If I would see the "antique" code and if I was familiar with JFreeChart 0.9.xx, I could possibly help. Neither condition is fulfilled at present.ss wrote: Could you pls tell me how to update the "antique" codes using "StandardLegend"?

Even without knowing how the legend is generated and can be customized using JFreeChart 0.9.xx, , it is possible to assume what the method StandardLegend.setDisplaySeriesShapes(true) is doing: it simply seems to set the shapes visible in the legend. That suggests that the appearance of the series in the chart and in the legend can be changed independently and you have to worry about getting it consistent.
In JFreeChart 1.0.x this is no longer necessary be default.
The LegendTitle contains a LegendItemSource that returns a LegendItemCollection which consists of individual LegendItems which in turn have properties like shapeVisible, shapeFilled (both boolean, for more please check the API) and which are used by the LegendTitle to build the legend. LegendItemSource is an interface that is implemented by e. g. XYPlot, CategoryPlot and a couple of renderers.
If you let JFreeChart create the legend of the chart automatically (by setting the createLegend flag in the respective constructor to true), a LegendTitle will be created that uses the Plot as LegendItemSource. The Plot in turn retrieves the information about the different flags and the Shape/Stroke/Paint information that are required to construct the LegendTitles from the renderer. You can check the source code which is available online to see in detail how this is achieved.
By this mechanism it is assured that the display information of the series in the legend and in the plot come from the same source (i.e. the renderer) and are thus consistent.
So my proposal about "updating the antique code" would be to simply remove all methods where the contents of the "StandardLegend" are changed so that a default legend is created and then check whether this default legend needs any further change at all!
Regards, paradoxoff
Paradox off,
Your reply is so helpful! Thanks a lot
ss.
Below are the codes of the story (if you want to have a look, for fun)
m_chart = new JFreeChart("My Plot", titleFont, m_plot, true);
...
--- Antique codes ---
StandardLegend legend = (StandardLegend) m_chart.getLegend();
legend.setDisplaySeriesShapes(true);
--- New codes that I now know is unnecessary from your reply ---
LegendTitle legendTitle = (LegendTitle) m_chart.getLegend();
LegendItemSource[] sources = legendTitle.getSources();
for (int i=0;i<sources.length ;i++)
{
LegendItemCollection items = sources.getLegendItems();
if (items != null)
{
for (int j=0;j<items.getItemCount();j++)
{
LegendItem item = items.get(j);
LegendGraphic lg = new LegendGraphic(item.getShape(),item.getFillPaint());
lg.setShapeVisible(true);
}
}
}
Your reply is so helpful! Thanks a lot

ss.
Below are the codes of the story (if you want to have a look, for fun)
m_chart = new JFreeChart("My Plot", titleFont, m_plot, true);
...
--- Antique codes ---
StandardLegend legend = (StandardLegend) m_chart.getLegend();
legend.setDisplaySeriesShapes(true);
--- New codes that I now know is unnecessary from your reply ---
LegendTitle legendTitle = (LegendTitle) m_chart.getLegend();
LegendItemSource[] sources = legendTitle.getSources();
for (int i=0;i<sources.length ;i++)
{
LegendItemCollection items = sources.getLegendItems();
if (items != null)
{
for (int j=0;j<items.getItemCount();j++)
{
LegendItem item = items.get(j);
LegendGraphic lg = new LegendGraphic(item.getShape(),item.getFillPaint());
lg.setShapeVisible(true);
}
}
}