2

I would like to be able to set the number of decimal places for point labels. Currently, my point labels are overlapping one another like so:

https://i.stack.imgur.com/1aQ4q.png

Current label implementation is trivial:

myXYPlot.setPointLabelFormatter(new PointLabelFormatter(Color.BLACK));
davidleejy
  • 585
  • 4
  • 9

3 Answers3

3

You can implement the PointLabeler interface to get the behavior you're after; you need to set the PointLabeler for each series that should use the custom formatting. For example:

series1.setPointLabeler(new PointLabeler() {
    DecimalFormat df = new DecimalFormat("###.###");

    @Override
    public String getLabel(XYSeries series, int index) {
        return df.format(series.getY(index));
    }
});

It's a little less intuitive than applying formatting to domain and range labels but was necessary in order to allow each series to have its own point labeling scheme.

Nick
  • 8,181
  • 4
  • 38
  • 63
1

The answer provided by Nick is for old version. The PointLabeler method has been moved into LineAndPointFormatter. The latest working example has been provided by Nick in another thread: https://stackoverflow.com/a/39482297/9969285

Jemshid
  • 15
  • 4
0

PointLabelFormatter() and the other *Formatter() APIs don't offer a way to choose your decimal format. My guess is that you need to format your series data prior to calling plot.addSeries().

bstar55
  • 3,542
  • 3
  • 20
  • 24