In desktop Java project I used StandardXYToolTipGenerator
for generating tooltips on chart.
Renderer was configured as below:
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} - {2} ({1})",new SimpleDateFormat("HH:mm:ss"), NumberFormat.getNumberInstance()));
Where {2}
is value (example 1.149431) but when I am using NumberFormat
it format itself and return value 1.149, I want get precisely rounding. How to get it? Any idea?
I tried extend NumberFormat
class, but method format(double number)
is final...
NumberFormat.getNumberInstance()
"Returns a general-purpose number format for the current default FORMAT
locale." You can adjust the rounding mode and the number of digits as desired. Based on this example, the fragment below retains the default rounding mode and specifies five digits.
NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumFractionDigits(5);
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
"{2}", DateFormat.getDateInstance(), format));
As an aside, verify that your chosen SimpleDateFormat
is appropriate for for your target locale.