Extend legend with an own image

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ludi81
Posts: 4
Joined: Thu Dec 17, 2009 2:54 pm
antibot: No, of course not.

Extend legend with an own image

Post by ludi81 » Thu Dec 17, 2009 2:59 pm

Hi,

I would like to extend the legend with an own image.
Ideally the legend looks like a table.
1. column contains the color of the part (in a dot)
2. column contains the name (as a string)
3. column contains the individual image (png)

Im not able to draw an image within the legend, does anyone have an idea?

Thanks a lot!
Ludi

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

Re: Extend legend with an own image

Post by paradoxoff » Thu Dec 17, 2009 9:06 pm

You will have to do some coding to achieve what you want.
A LegendTitle is composed of several blocks. For every "legend entry", you have two blocks, one is an instance of LegendGraphic (which hold the shape) amd the other is an instance of LabelBlock (which displays the text). These individual blocks are put together in LegendTitle.createLegendItemBlock(LegendItem item).
Suggestion: extend LegendTitle and override createLegendItemBlock(LegendItem item). In addition to the LegendGraphic lg, and the LabelBlock labelBlock, you could add an instance of ImageTitle to the BlockContainer "result" which is created in createLegendItemBlock.
If you need to have columns of equal width, even for labels of different size, this approach won´t give good results. E. g. the labelBlocks of the different rows will not be aligned, because the different BlockContainers of the different rows are not aware of each other. In order to enforce a strict grid-line arrangement, you could also override fetchLegendItems() of the LegendTitle class and use a GridArrangement.
If you want to have different images per-series, you would probabaly also need an extended LegendItem class which can hold that information, and an extended renderer to provide that information.
All in all this looks like "doable with reasonable effort". Good luck anyways!

ludi81
Posts: 4
Joined: Thu Dec 17, 2009 2:54 pm
antibot: No, of course not.

Re: Extend legend with an own image

Post by ludi81 » Fri Dec 18, 2009 12:29 pm

paradoxoff wrote:You will have to do some coding to achieve what you want.
A LegendTitle is composed of several blocks. For every "legend entry", you have two blocks, one is an instance of LegendGraphic (which hold the shape) amd the other is an instance of LabelBlock (which displays the text). These individual blocks are put together in LegendTitle.createLegendItemBlock(LegendItem item).
Suggestion: extend LegendTitle and override createLegendItemBlock(LegendItem item). In addition to the LegendGraphic lg, and the LabelBlock labelBlock, you could add an instance of ImageTitle to the BlockContainer "result" which is created in createLegendItemBlock.
If you need to have columns of equal width, even for labels of different size, this approach won´t give good results. E. g. the labelBlocks of the different rows will not be aligned, because the different BlockContainers of the different rows are not aware of each other. In order to enforce a strict grid-line arrangement, you could also override fetchLegendItems() of the LegendTitle class and use a GridArrangement.
If you want to have different images per-series, you would probabaly also need an extended LegendItem class which can hold that information, and an extended renderer to provide that information.
All in all this looks like "doable with reasonable effort". Good luck anyways!
Thank you very much for your ideas! The first version works great!

ludi81
Posts: 4
Joined: Thu Dec 17, 2009 2:54 pm
antibot: No, of course not.

Re: Extend legend with an own image

Post by ludi81 » Fri Dec 18, 2009 12:29 pm

paradoxoff wrote:You will have to do some coding to achieve what you want.
A LegendTitle is composed of several blocks. For every "legend entry", you have two blocks, one is an instance of LegendGraphic (which hold the shape) amd the other is an instance of LabelBlock (which displays the text). These individual blocks are put together in LegendTitle.createLegendItemBlock(LegendItem item).
Suggestion: extend LegendTitle and override createLegendItemBlock(LegendItem item). In addition to the LegendGraphic lg, and the LabelBlock labelBlock, you could add an instance of ImageTitle to the BlockContainer "result" which is created in createLegendItemBlock.
If you need to have columns of equal width, even for labels of different size, this approach won´t give good results. E. g. the labelBlocks of the different rows will not be aligned, because the different BlockContainers of the different rows are not aware of each other. In order to enforce a strict grid-line arrangement, you could also override fetchLegendItems() of the LegendTitle class and use a GridArrangement.
If you want to have different images per-series, you would probabaly also need an extended LegendItem class which can hold that information, and an extended renderer to provide that information.
All in all this looks like "doable with reasonable effort". Good luck anyways!
Thank you very much for your ideas! The first version works great!

raulh
Posts: 1
Joined: Mon Feb 20, 2017 12:08 am
antibot: No, of course not.

Re: Extend legend with an own image

Post by raulh » Mon Feb 20, 2017 12:12 am

ludi81 wrote:
paradoxoff wrote:You will have to do some coding to achieve what you want.
A LegendTitle is composed of several blocks. For every "legend entry", you have two blocks, one is an instance of LegendGraphic (which hold the shape) amd the other is an instance of LabelBlock (which displays the text). These individual blocks are put together in LegendTitle.createLegendItemBlock(LegendItem item).
Suggestion: extend LegendTitle and override createLegendItemBlock(LegendItem item). In addition to the LegendGraphic lg, and the LabelBlock labelBlock, you could add an instance of ImageTitle to the BlockContainer "result" which is created in createLegendItemBlock.
If you need to have columns of equal width, even for labels of different size, this approach won´t give good results. E. g. the labelBlocks of the different rows will not be aligned, because the different BlockContainers of the different rows are not aware of each other. In order to enforce a strict grid-line arrangement, you could also override fetchLegendItems() of the LegendTitle class and use a GridArrangement.
If you want to have different images per-series, you would probabaly also need an extended LegendItem class which can hold that information, and an extended renderer to provide that information.
All in all this looks like "doable with reasonable effort". Good luck anyways!
Thank you very much for your ideas! The first version works great!
Hi ludi81 can you post the code as example please.

Locked