Point Labeling Tools in 0.5.1
Two new features for labeling data have been added to Androidplot in 0.5.1:PointLabelFormatter
First, the LineAndPointFormatter has been updated to support drawing text strings above the points themselves. Using this functionality is as simple as passing in an instance of PointLabelFormatter to your addSeries calls:
1 2 3 4 5 |
plot.addSeries( series2, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null, new PointLabelFormatter(Color.WHITE))); // the NEW PointLabelFormatter |
1 2 3 4 5 |
plot.addSeries(series2, new LineAndPointFormatter( Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null, (PointLabelFormatter) null)); |
PointLabeler
While PointLabelFormatter provides a convenient solution to those wanting to label every point in a series, this functionality is rather limited. Those who need more control can leverage the changes to LineAndPointRenderer.setPointLabeler(PointLabeler) to register a custom PointLabeler. It's important to note that you use PointLabeler in conjunction with a PointLabelFormatter; if you passed in null as shown above, then no matter what you do in your custom PointLabeler, no labels will appear. Here's a simple example that uses a custom PointLabeler to display even numbered indexes:
1 2 3 4 5 6 7 8 |
LineAndPointRenderer lpr = (LineAndPointRenderer) plot.getRenderer(LineAndPointRenderer.class); lpr.setPointLabeler(new PointLabeler() { @Override public String getLabel(XYSeries series, int index) { return index % 2 == 0 ? index + "" : ""; } }); |
Pingback: Format point label on XYPlot - Technology
As of Androidplot 1.0.x documentation has been moved into the github repo. Apologies for the confusion!