1

I am creating a Bar Chart:

final JFreeChart result = ChartFactory.createBarChart(TITLE, // chart title
    X_TITLE, // domain axis label
    Y_TITLE, // range axis label
    dataset, // data
    PlotOrientation.HORIZONTAL, // the plot orientation
    true, // legend
    true, // tooltips
    false // urls
    );

I then added a ChartMouseListener as described here.

When I click on a legend item, "LegendItemEntity: seriesKey=null, dataset=null" is displayed.

How do I access the legend text for the corresponding item?

Community
  • 1
  • 1
pgerstoft
  • 489
  • 6
  • 15

1 Answers1

1

Starting from org.jfree.chart.demo.BarChartDemo1 and adding the same ChartMouseListener to the source yields results like this:

LegendItemEntity: seriesKey=First, dataset=org.jfree.data.category.DefaultCategoryDataset@d9510071
LegendItemEntity: seriesKey=Second, dataset=org.jfree.data.category.DefaultCategoryDataset@d9510071
LegendItemEntity: seriesKey=Third, dataset=org.jfree.data.category.DefaultCategoryDataset@d9510071

If you're geting a different result, an sscce may help.

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