0

I am trying to set a series visible or invisible based on click on the legend item; but plot.getRenderer() returns null, so I cannot set the series visibility. Here is the code:

private void legendMouseClick(ChartMouseEvent event) {
    ChartEntity entity = event.getEntity();
    if (entity instanceof LegendItemEntity) {
        //*
        LegendItemEntity itemEntity = (LegendItemEntity) entity;
        XYDataset dataset = (XYDataset) itemEntity.getDataset();
        int index = dataset.indexOf(itemEntity.getSeriesKey());
        CombinedDomainXYPlot plot = (CombinedDomainXYPlot) event.getChart().getPlot();
        XYItemRenderer renderer = plot.getRenderer(); //renderer is null

        if (renderer == null) {
          return;
        }
        System.out.println("Renderer count: " + plot.getRendererCount());
        renderer.setSeriesVisible(index, !renderer.isSeriesVisible(index), false);
    }
}

Thanks for help

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • See `getSubplots()`. "The returned list may be empty, but is never `null`". If this is not a duplicate, please edit your question to include a [mcve] that shows the problem you describe. – trashgod May 17 '17 at 08:32
  • getSubplots() works fine for me - from subplots I can see renderers, thank you :-) problem solved – Michal K. May 17 '17 at 09:11

0 Answers0