1

When my chart gets a lot of data the point labels overlap each other and as a result I want to give the user an option to turn them off by clicking a button but I can't find anything in the documentation on how to do this. Below is how I setup the point labels when the chart is created.

BarFormatter series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);'
PointLabelFormatter  plf = new PointLabelFormatter();
plf.getTextPaint().setTextSize(18);
plf.getTextPaint().setColor(Color.BLACK);
series1Format.setPointLabelFormatter(plf);
Mark
  • 183
  • 4
  • 12

2 Answers2

2

Have you tried setting PointLabelFormatter to null inside your BarFormatter instance?

series1format.setPointLabelFormatter(null);

Then to turn the labels back on just add it back with your original method:

series1Format.setPointLabelFormatter(plf);
Nick
  • 8,181
  • 4
  • 38
  • 63
1

Now sure if this is the best way to turn on/off the point labels but if works :)

private void TogglePointLabelVisibility(boolean ShowLabels)
{
    BarFormatter series1Format = new BarFormatter();

    if(ShowLabels)
    {
        series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);
        PointLabelFormatter  plf = new PointLabelFormatter();
        plf.getTextPaint().setTextSize(18);
        plf.getTextPaint().setColor(Color.BLACK);
        series1Format.setPointLabelFormatter(plf);
    }
    else
    {
        series1Format.setPointLabelFormatter(null);
    }

    SeriesAndFormatterList<XYSeries, XYSeriesFormatter> renderer = plot.getSeriesAndFormatterListForRenderer(BarRenderer.class);
    renderer.setFormatter(series1, series1Format);

}
Mark
  • 183
  • 4
  • 12