legend in thermometer plot (to explain subrange colors)?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gkatzusr
Posts: 1
Joined: Thu Oct 02, 2014 1:59 pm
antibot: No, of course not.

legend in thermometer plot (to explain subrange colors)?

Post by gkatzusr » Thu Oct 02, 2014 2:16 pm

hi all;
I would like to add an explanation (legend per my understanding displayed somewhere on the chart) to a thermometer chart in order to explain subrange colors. for example:
[red]=hot
[yellow]=cool
[blue]=cold
I was able to define the sub ranges and their color, but I cant seem to find the way to add the descriptive text to these colors.
your help is appreciated.,
thanks.

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

Re: legend in thermometer plot (to explain subrange colors)?

Post by david.gilbert » Wed Oct 08, 2014 8:37 pm

To add a legend with manually specified entries, you can do something like this:

Code: Select all

            LegendTitle legend = new LegendTitle(new LegendItemSource() {
                @Override
                public LegendItemCollection getLegendItems() {
                    LegendItemCollection items = new LegendItemCollection();
                    items.add(new LegendItem("Item A", Color.RED));
                    items.add(new LegendItem("Item B", Color.GREEN));
                    items.add(new LegendItem("Item C", Color.BLUE));
                    return items;
                }
            });
            legend.setPosition(RectangleEdge.RIGHT);
            chart.addLegend(legend);
David Gilbert
JFreeChart Project Leader

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

Locked