Custom draw legends/subtitles.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
FedorkZ
Posts: 6
Joined: Wed Sep 03, 2014 3:15 pm
antibot: No, of course not.

Custom draw legends/subtitles.

Post by FedorkZ » Mon Nov 17, 2014 1:54 pm

Hi!
I would like to add custom legend (or annotation) that is drawn in unusual way. For example I would like add Mean and Median markers explanation to BoxAndWhiskers chart. Or scale bar to XYPlot (Like scale on the google maps). What class should I use as a parent? And how are coordinates measured?
Thanx in advance!

FedorkZ
Posts: 6
Joined: Wed Sep 03, 2014 3:15 pm
antibot: No, of course not.

Re: Custom draw legends/subtitles.

Post by FedorkZ » Mon Nov 17, 2014 2:42 pm

Seems that I have found how make mean and median legend:
I used LegendTitle class fot this purpose.

Code: Select all

   	LegendTitle legend = new LegendTitle(new LegendItemSource() {
            @Override
            public LegendItemCollection getLegendItems() {
                LegendItemCollection items = new LegendItemCollection();
                
                int aRadius = 5;
                Shape ellipseShape = new Ellipse2D.Double(5 + aRadius , 5 - aRadius, aRadius * 2, aRadius * 2);
                
                items.add(new LegendItem("Ellipse", "", "", "", medianShape, Color.BLACK));
                return items;
            }
        });
        legend.setPosition(RectangleEdge.RIGHT);
        chart.addLegend(legend);   

Locked