将系列可见性设置为False也会将其隐藏在图例中 [英] Setting series visiblity to False also hides it from the legend

查看:123
本文介绍了将系列可见性设置为False也会将其隐藏在图例中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JFreeChart.

I am using JFreeChart.

当我单击图例"项目时,我已放置了一个侦听器.在侦听器中,我将单击的系列设为隐形.但作为副作用,该系列也从《传奇》中消失了.

When i click on a Legend item i have put a listener. In the listener i make the series that was clicked invisble. But as a side effect the series also vanishes from the Legend.

我不希望该系列从传说中消失.我该怎么做,以便我可以在剧情中显示/隐藏系列,但不影响图例.

I do not want the series to vanish from the legend. What can i do so that i can show/hide series on the plot but not affect the legend.

使用plot.setFixedLegendItems(list)将图例设置为固定会导致其他鼠标效果停止工作(在数据点的鼠标悬停时,系列行当前会变粗,并且在图例中相同).

Setting the Legend to be fixed using plot.setFixedLegendItems(list) cause other mouse effects to stop working (on mouse over of data point the series line currently becomes thicker and the same in the legend).

chartPanel.addChartMouseListener(new ChartMouseListener() {
    @Override
    public void chartMouseClicked(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());
            XYPlot plot = (XYPlot) event.getChart().getPlot();

            //set the renderer to hide the series
            XYItemRenderer renderer = plot.getRenderer();
            renderer.setSeriesVisible(index, !renderer.isSeriesVisible(index), false);
            renderer.setSeriesVisibleInLegend(index, true, false);
            //*/        
        }
    }
});

推荐答案

XYPlot类中的getLegendItems()方法进行可见性检查,因此您可以将XYPlot子类化并覆盖此方法(或直接对其进行修改)如果您要构建自己的JFreeChart自定义版本).

It is the getLegendItems() method in the XYPlot class that does the visibility checking, so you could subclass XYPlot and override this method (or modify it directly if you want to build your own custom version of JFreeChart).

这篇关于将系列可见性设置为False也会将其隐藏在图例中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆