Is it possible to add Legend to the plot in JFreeChart?

后端 未结 3 1060
北海茫月
北海茫月 2020-11-27 22:19

I\'m trying to add a legend under the plot in scattered chart as shown below. Anyone knows if this is possible?

Before:

3条回答
  •  臣服心动
    2020-11-27 22:38

    Extending StandardXYItemLabelGenerator is often a useful approach, but the supplied constructors may suffice. For this generator, the MessageFormat ArgumentIndex values correspond to the series name, domain and range.

    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2); // etc.
    XYItemLabelGenerator generator =
        new StandardXYItemLabelGenerator("{0} {1} {2}", format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);
    

    In addition, you can control individual series labeling with

    renderer.setSeriesItemLabelsVisible(true);
    

提交回复
热议问题