1

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

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Elliot
  • 509
  • 1
  • 3
  • 13

1 Answers1

2

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);
    }
});
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks for that trashgod - it worked! Since my chart uses subcategories I'm wondering if there is anyway to parse the series {0} placeholder into the 2 parts. My series values come in as "Skill (Emp)) and I would like to separate the two in the tool-tips or only show one of them. – Elliot May 01 '16 at 17:20
  • You may have to fiddle with `String::indexOf()` and `String::substring()` in a custom `generateToolTip()`. Ping me if here if you post a new question on this topic. – trashgod May 01 '16 at 20:20
  • Hi trashgod - sorry I'm new to this - are you suggesting I start a new question on formating the {0} value? And how do I piing you - is it just usiing @trashgod? – Elliot May 01 '16 at 23:14
  • @Elliot: Yes & yes. You'll get better answers if you focus on the problem in isolation, e.g. are you stuck overriding a method or using string methods. I consider tooltips a view decoration, but you may decide to alter your model (dataset). See also this [design discussion](http://www.jfree.org/forum/viewtopic.php?f=3&t=117562). – trashgod May 02 '16 at 01:25