mpandroidchart-如何更新限制线位置?

发布于 2025-02-10 00:29:40 字数 247 浏览 2 评论 0原文

我正在尝试动态更新极限线的位置。现在,我只能在创建线路时设置位置。稍后如何更改位置?

        LimitLine ll = new LimitLine(0f, "");
        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.addLimitLine(ll);

        // Set new position here...
        

I am trying to dynamically update the position of a LimitLine. For now, I can only set the position when I create the line. How can I change the position later?

        LimitLine ll = new LimitLine(0f, "");
        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.addLimitLine(ll);

        // Set new position here...
        

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好菇凉咱不稀罕他 2025-02-17 00:29:40

更新您的限制线和Indoke Chart.invalidate(),然后更改了位置。在演示代码linechartactivity.java中,以这种方式进行了限制,限制线将自动更改:

    @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    // redraw
    seekBarY.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (seekBarY.getProgress() < seekBarY.getMax()) {
                seekBarY.setProgress(seekBarY.getProgress() + 1);
            }
        }
    }, 500);

    double percent = seekBarY.getProgress() * 1.0 / seekBarY.getMax();

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.removeAllLimitLines();
    LimitLine ll = new LimitLine((float)(percent * 50), "");
    ll.setLineColor(Color.BLACK);
    ll.setLineWidth(5f);
    leftAxis.addLimitLine(ll);
    chart.invalidate();
}

enter image description here

Update your limitline and invoke chart.invalidate() then the position is changed. In the demo code LineChartActivity.java, onProgressChanged, by this way, the limitline will changed automatically:

    @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    // redraw
    seekBarY.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (seekBarY.getProgress() < seekBarY.getMax()) {
                seekBarY.setProgress(seekBarY.getProgress() + 1);
            }
        }
    }, 500);

    double percent = seekBarY.getProgress() * 1.0 / seekBarY.getMax();

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.removeAllLimitLines();
    LimitLine ll = new LimitLine((float)(percent * 50), "");
    ll.setLineColor(Color.BLACK);
    ll.setLineWidth(5f);
    leftAxis.addLimitLine(ll);
    chart.invalidate();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文