Michela Montano
Michela Montano

Reputation: 13

JFreechart - How to add extra info in tooltip

The Problem

I'm trying to show additional info in tooltip.

Tools Used

I'm using the StandardCategoryToolTipGenerator.

What I have tried so far

The original values retrieved from database are elaborated before they are associated to the CategorydataSet.

The Goal to Achieve

I would like to show the original value in the tooltip.. Is it possible? I only can load the {0}, {1}, {2} values, maybe there's a way to store additional info in categorydata set?

Thank you for support,
Michela

Upvotes: 1

Views: 280

Answers (1)

Catalina Island
Catalina Island

Reputation: 7126

You can extend StandardCategoryItemLabelGenerator and override generateToolTip. With access to the dataset, you can put pretty much anything in the tooltip. For example,

CategoryPlot plot = (CategoryPlot) chart.getPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(){

    @Override
    protected String generateLabelString(CategoryDataset dataset, int row, int col) {
        return dataset.getColumnKey(col) + " " + dataset.getValue(row, col);
    }
});

Upvotes: 2

Related Questions