MpAndroidChart在限制线之间设置背景 [英] MpAndroidChart set background between limit lines

查看:570
本文介绍了MpAndroidChart在限制线之间设置背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MpAndroidChart库.我需要实现一种设计,在其中我需要对两条极限线之间的区域进行着色.我已附上一张图片以供参考.我尝试了多种方法,但未能实现.我是第一次使用该库.谁能帮助我有关如何实现这一目标.

I a using MpAndroidChart library. I need to implement a design where I need to color the area between two limit lines. I have attached an image for reference. I have tried multiple ways but I have failed to achieve it. I am using this library for the first time. Can anyone help me about how this could be achieved.

您可以看到折线图后面的绿色阴影.这是极限.我需要得到绿色的阴影

As you can see the green shade behind the line graph. Which is the limit. I need to get that green shade

预先感谢

奥迪·雷迪(Anudeep Reddy).

Anudeep Reddy.

推荐答案

我遇到了同样的问题,但是又有了不同的解决方法,而不必继承LineChart.使用画布绘制矩形是可行的,但是您必须将图表坐标转换为画布坐标.您不能使用单个限制线,因为限制线的宽度.我使用的解决方法是简单地遍历极限线以在我的范围内创建一个矩形.

I had the same problem but reached a different workaround without having to subclass the LineChart. Using canvas to draw the rectangle works, but you have to translate your charts coordinates to the canvas coordinates. You cannot use a single limit line as there is a limit to the width of the line. The workaround I used was to simply loop through limit lines to create a rectangle within my range.

    float increment = (rangeHigh - rangeLow) / 20;
    float metricLine = rangeLow;

    for(int i = 0; i < 20; i++) {
        LimitLine llRange = new LimitLine(metricLine, "");
        llRange.setLineColor(Color.parseColor("#b5eb45"));
        llRange.setLineWidth(10f);
        leftAxis.addLimitLine(llRange);
        metricLine = metricLine + increment;
    }

这篇关于MpAndroidChart在限制线之间设置背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆