setDisplaySeriesShapes in version 1.0 ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
knopper

setDisplaySeriesShapes in version 1.0 ?

Post by knopper » Wed Mar 23, 2005 3:36 pm

How can i do like this

final StandardLegend sl = (StandardLegend) chart.getLegend();
sl.setDisplaySeriesShapes(true);

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Mar 24, 2005 10:34 am

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

Post by khipras » Thu Jun 23, 2005 7:20 pm

You must get the plot renderer and cast to XYLineAndShapeRenderer

myxyshape.setDefaultShapesVisible(true);
myxyshape.setDefaultShapesFilled(false);
...

ss
Posts: 22
Joined: Sun Aug 03, 2008 3:17 pm

Could you pls give an example code?

Post by ss » Sun Aug 03, 2008 3:25 pm

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!

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Could you pls give an example code?

Post by paradoxoff » Sun Aug 03, 2008 6:04 pm

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);
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
Posts: 22
Joined: Sun Aug 03, 2008 3:17 pm

Post by ss » Mon Aug 04, 2008 2:28 am

Paradoxoff,

Yeah, I am customizing the displayinf of legend. Actually I am updating the old codes calling jfreechart 0.9.15 to 1.0.10.

Could you pls tell me how to update the "antique" codes using "StandardLegend"?

Thanks!

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Post by paradoxoff » Mon Aug 04, 2008 8:20 am

ss wrote: Could you pls tell me how to update the "antique" codes using "StandardLegend"?
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. :?
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

ss
Posts: 22
Joined: Sun Aug 03, 2008 3:17 pm

Post by ss » Mon Aug 04, 2008 1:16 pm

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);
}
}
}

Locked