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

相關文章
相關標籤/搜索