Elliot
Elliot

Reputation: 535

Add tooltips to a jfreechart stacked bar char with subcategories

I've developed an application based on the jFreeChart StackedBarChartDemo4.java program.

The image produced by my modified demo looks like this, but there is no attempt in the demo code to add tool-tips to the segmented bars.

So how can I add a tool-tip for each of the employees displayed in each bar?

Thanks Elliot

StackedBarChartDemo4

Upvotes: 1

Views: 1337

Answers (1)

trashgod
trashgod

Reputation: 205775

Add a concrete CategoryToolTipGenerator to your chosen renderer, for example:

renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

The default values are described here, but you can override generateToolTip() and access the CategoryDataset to display anything at all.

My series values come in as "Skill (Emp)" and I would like to separate the two.

As a concrete example, the following custom renderer would display just the "Emp" portion of the series key.

renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator() {
    @Override
    public String generateToolTip(CategoryDataset dataset, int row, int column) {
        String s = super.generateToolTip(dataset, row, column);
        int b = s.indexOf('(', 1) + 1;
        int e = s.indexOf(')');
        return s.substring(b, e);
    }
});

Upvotes: 2

Related Questions