Remove series indicator/plot legend AndroidPlot

喜夏-厌秋 提交于 2019-12-07 04:10:08

问题


I realise AndroidPlot has a forum but it isn't the most active so i'll chance my arm here...

I'm trying to remove the series indicator or plot legend from my XY plot using the AndroidPlot library. I don't want to remove the series from the plot itself, just the legend.

I've seen it done on AndroidPlot examples but with the limited documentation it's difficult to find methods to do the stuff like remove the legen


回答1:


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.




回答2:


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().




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/13413333/remove-series-indicator-plot-legend-androidplot

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