Sam
Sam

Reputation: 1327

JFreeChart customize BoxAndWhiskerToolTip

I am adding tooltip to Box and Whisker plot.

final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
String tooltipformat = "Max: {5}\nQ3: {7}\nQ1: {6}\nMin: {4}\nMean: {2}\nMedian: {3}";
renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator(tooltipformat,NumberFormat.getNumberInstance()));

I get the result below.

enter image description here

Instead of getting the tooltip label in a column, I got it in a row. Why does the \n is useless?

Upvotes: 1

Views: 173

Answers (2)

trashgod
trashgod

Reputation: 205775

Because ChartPanel uses a ToolTipManager.sharedInstance(), you can break multi-line tooltips as suggested here and here. As another example, the following changes to BarChartDemo1, seen here, produce the results illustrated below.

BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(
    "<html>Series: {0}<br>Category: {1}<br>Value: {2}</html>",
    NumberFormat.getInstance()));

image

Upvotes: 1

Sam
Sam

Reputation: 1327

Use HTML will do.

String tooltipformat = "<html><body>Max: {5}<br>Q3: {7}<br>Median: {3}<br>Q1: {6}<br>Min: {4}<br>Mean: {2}</body></html>";
renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator(tooltipformat,NumberFormat.getNumberInstance()));

Upvotes: 1

Related Questions