-
Notifications
You must be signed in to change notification settings - Fork 32
howto change legend labels
GRAL plots provide different types of legends with different properties. For example, pie plots provide legends of the type ValueLegend
which show items for each value in the data set. The values are used as labels by default. To set which labels are used by ValueLegend
you can change its labelColumn
property.
Given we have a pie plot with the following data:
7 | "Spam" |
42 | "Ham" |
We can then tell the legend to use the second column to render the labels:
ValueLegend legend = (ValueLegend) plot.getLegend();
legend.setLabelColumn(1);
or as a one-liner:
((ValueLegend) plot.getLegend()).setLabelColumn(1);
The labelFormat
property of ValueLegend
allows a custom formatting of label values. This could be used to display date or time values, or to change the format of numbers. labelFormat
stores an object of type java.text.Format
which specifies how to format the labels.
This example uses java.text.DateFormat
to format date values:
DateFormat customFormat = DateFormat.getDateInstance();
((ValueLegend) plot.getLegend()).setLabelFormat(customFormat);
API docs for ValueLegend