【问题标题】:Remove a lengend from an XYPlot从 XY 图中删除图例
【发布时间】:2014-08-01 11:23:28
【问题描述】:

我在我的项目中使用 AndroidPlot,到目前为止它非常棒。这就是我得到的。

现在我正在尝试从图例中删除其中一个系列指标。实际上我只想保留第一个(蓝色的),因为其他的都是不言自明的。

我不是在询问如何自行删除图例(有关该问题,请参阅 https://stackoverflow.com/a/13413758/665823)。

如果有人可以帮助我,我会很棒。提前致谢。

【问题讨论】:

  • 完全不确定你能做到这一点。最好的办法是查看 ledged 小部件的来源。您可以扩展它来调整功能。
  • @lfor 我设法做到了这一点,而无需修改源代码。有兴趣可以看我的回答。无论如何感谢您的建议:)

标签: android androidplot


【解决方案1】:

我终于找到了一个可以让我做我需要做的事情的 tweek。为了实现这一点,必须首先将我需要显示的系列添加到情节中,而不是我需要隐藏的系列:

// I add the blue serie first
LineAndPointFormatter mFormat = new LineAndPointFormatter();
mFormat.configure(context, R.xml.plot_blue);
graphView.addSeries(serieMesures, mFormat);

// I add the other colors after
for (XYSeries serie : seriesSeuils) {
     LineAndPointFormatter sFormat = new LineAndPointFormatter();
     if (serie.getTitle().equals("RED") {
        sFormat.configure(context, R.xml.plot_red);
     } 
     else if (serie.getTitle().equals("ORANGE")) {
        sFormat.configure(context, R.xml.plot_orange);
     }
     else if (serie.getTitle().equals("YELLOW")) {
        sFormat.configure(context, R.xml.plot_yellow);
     }
     graphView.addSeries(serie, sFormat);
}

然后我刚刚创建了一个图例,其中只有足够的空间来显示我需要的系列(在我的情况下只是第一个)。

// This is what does the trick! A Table with 1 line and 1 column 
// so the other series can't be rendered in the LegendWidget
graphView.getLegendWidget().setTableModel(new DynamicTableModel(1, 1));

// Other customizations (size and position)
graphView.getLegendWidget().setSize(new SizeMetrics(55, SizeLayoutType.ABSOLUTE, legendWith, SizeLayoutType.ABSOLUTE));
graphView.getLegendWidget().setPositionMetrics(
     new PositionMetrics(20,
                         XLayoutStyle.ABSOLUTE_FROM_RIGHT,
                         20,
                         YLayoutStyle.ABSOLUTE_FROM_TOP,
                         AnchorPosition.RIGHT_TOP));
graphView.getLegendWidget().setBackgroundPaint(bgPaint);
graphView.getLegendWidget().setTextPaint(txPaint);
graphView.getLegendWidget().setBorderPaint(brPaint);
graphView.getLegendWidget().setPadding(10, 1, 10, 1);

瞧!

【讨论】:

    猜你喜欢
    • 2018-05-31
    • 2021-12-20
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 2022-06-07
    • 1970-01-01
    相关资源
    最近更新 更多