Take the 2-minute tour ×

I am using a JFreeChart Bar Chart in a Swing GUI with several category labels. For each label there are several subcategory labels. There are many bars. And therefore each one is very small and barely visible. I want to be able to zoom in on a particular category.

Is it possible to make the category label clickable? By, for example, adding a listener to it? Then I would click on a category label and set the displayed chart to only show that category.

If not, what would be another solution for making the bars more visible?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

The simplest approach is to enable tooltips in your ChartFactory.createBarChart(). Alternatively, use a ChartMouseListener, shown here, to perform some other action.

Editing your question to include an sscce might help suggest which approach to use.

share|improve this answer
add comment

The pseudo-code for the mouse listener I used:

chartPanel.addChartMouseListener(new ChartMouseListener() {

  public void chartMouseClicked(ChartMouseEvent e) {
    if (e.getEntity().getClass() != CategoryLabelEntity.class) {

    CategoryLabelEntity entity = (CategoryLabelEntity) e.getEntity();
    String category = (String) entity.getKey();

    //Using another dataSet, create a zoomedInChart 
    //composed only of values from that dataset

  public void chartMouseMoved(ChartMouseEvent e) {
    // do nothing

share|improve this answer
+1 setMouseWheelEnabled() may also be worth a look. –  trashgod May 4 '12 at 19:07
add comment

Your Answer


