显示/隐藏点标签Androidplot

时间:2014-08-19 01:56:23

标签: android charts androidplot

当我的图表获取大量数据时,点标签会相互重叠,因此我想让用户选择通过单击按钮将其关闭,但我无法在文档中找到任何内容这该怎么做。下面是我在创建图表时设置点标签的方法。

BarFormatter series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);'
PointLabelFormatter  plf = new PointLabelFormatter();
plf.getTextPaint().setTextSize(18);
plf.getTextPaint().setColor(Color.BLACK);
series1Format.setPointLabelFormatter(plf);

2 个答案:

答案 0 :(得分:2)

您是否尝试在BarFormatter实例中将PointLabelFormatter设置为null?

series1format.setPointLabelFormatter(null);

然后重新打开标签,只需用原始方法将其添加回来:

series1Format.setPointLabelFormatter(plf);

答案 1 :(得分:1)

现在确定这是打开/关闭点标签的最佳方式,但是如果有效:)

private void TogglePointLabelVisibility(boolean ShowLabels)
{
    BarFormatter series1Format = new BarFormatter();

    if(ShowLabels)
    {
        series1Format = new BarFormatter(Color.rgb(51, 181, 229), Color.TRANSPARENT);
        PointLabelFormatter  plf = new PointLabelFormatter();
        plf.getTextPaint().setTextSize(18);
        plf.getTextPaint().setColor(Color.BLACK);
        series1Format.setPointLabelFormatter(plf);
    }
    else
    {
        series1Format.setPointLabelFormatter(null);
    }

    SeriesAndFormatterList<XYSeries, XYSeriesFormatter> renderer = plot.getSeriesAndFormatterListForRenderer(BarRenderer.class);
    renderer.setFormatter(series1, series1Format);

}