1

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?

pgerstoft
  • 489
  • 6
  • 15

2 Answers2

2

The pseudo-code for the mouse listener I used:

chartPanel.addChartMouseListener(new ChartMouseListener() {

  @Override
  public void chartMouseClicked(ChartMouseEvent e) {
    if (e.getEntity().getClass() != CategoryLabelEntity.class) {
      return;
    }

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

    //Using another dataSet, create a zoomedInChart 
    //composed only of values from that dataset
    chartPanel.setChart(zoomedInChart);
  }

  @Override
  public void chartMouseMoved(ChartMouseEvent e) {
    // do nothing
  }

});
pgerstoft
  • 489
  • 6
  • 15
1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045