Remove series indicator/plot legend AndroidPlot

点点圈 提交于 2019-12-05 11:40:46

OK I have the following code to do this. This is not tested on the very latest version but hopefully is still good.

    if (!mKeyOn)
        mDynamicPlot.getLayoutManager()
                .remove(mDynamicPlot.getLegendWidget());
    if (!mDomainLabelOn)
        mDynamicPlot.getLayoutManager().remove(
                mDynamicPlot.getDomainLabelWidget());

Looks like the trick is to get the layoutManager.

Looking at the code, setLegendWidget only updates the local handle for the LegendWidget but does not update the LayoutManager, which is what is actually invoked when it comes time to do the drawing. If you implement Ifor's (upvoted) suggestion you should have success since it interacts with the LayoutManager directly:

plot.getLayoutManager().remove(plot.getDomainLabelWidget());  

Another option is to hide the Legend like this:

plot.getLegendWidget().setVisible(false);

Provided (in light of the info above) that you are not also trying to substitute/remove the legend widget with a previous call to setLegendWidget().

You can also use Androidplot's XML Styling with Configurator and thanks to reflection remove plot legend by simply specifying it's visibility in XML layout file like this:

<com.androidplot.xy.XYPlot
...
    androidPlot.legendWidget.visible="false"
... />

If there is no need to change your legend dynamically, I think it's better to place such a styling in the XML file.

If you want to remove only one (or a specific) series legend from the legend widget simply use:

yourSeriesFormater.setLegendIconEnabled(false);

This worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!