MPAndroidChart实现蛛网图设置背景色

效果图:

image.png

上菜:git

一、RadarChartRenderer中drawWeb(Canvas c)设置以下大菜:

protected Path mDrawWebBg = new Path();
    protected void drawWeb(Canvas c) {
        Path surface = mDrawWebBg;
        surface.reset();
        boolean hasMovedToPoint = false;
        for (int i = 0; i < maxEntryCount; i += xIncrements) {
            if (mChart.isWebBackgroundEnable()) {
                //绘制背景的路径
                if (!hasMovedToPoint) {
                    surface.moveTo(p.x, p.y);
                    hasMovedToPoint = true;
                } else {
                    surface.lineTo(p.x, p.y);
                }
            }
        }
        if (mChart.isWebBackgroundEnable()) {
            //填充背景
            drawFilledPath(c, surface, mChart.getWebBackgroundColor(), mChart.getWebBackgroundFillAlpha());
        }
        surface.close();
复制代码

二、RadarChart中叫上服务员:

/** * 蛛网背景色默认关闭设置 */
    private boolean mWebBackgroundEnable = false;
    /** * 蛛网背景色,默认 */
    private int mWebBackgroundColor = -1;
    /** * 不透明度 (0-255) */
    private int mWebBackgroundFillAlpha = 180;
    
    /** * 设置蛛网背景色与透明度 * * @param color * @param fillAlpha */
    public void setWebBackgroundColor(boolean isOpen, int color, int fillAlpha) {
        this.mWebBackgroundEnable = isOpen;
        this.mWebBackgroundColor = color;
        this.mWebBackgroundFillAlpha = fillAlpha;
    }

    public int getWebBackgroundColor() {
        return mWebBackgroundColor;
    }

    public int getWebBackgroundFillAlpha() {
        return mWebBackgroundFillAlpha;
    }

    public boolean isWebBackgroundEnable() {
        return mWebBackgroundEnable;
    }
复制代码

三、该你喊服务员了:

chart.setWebBackgroundColor(true, Color.rgb(255, 189, 0), 180);
复制代码

餐厅地址:

github.com/hzl512/MPAn…github

喜欢就给个star呗~markdown

相关文章
相关标签/搜索