AAChartModel / AAChartCore

📈📊☕️☕️☕️An elegant modern declarative data visualization chart framework for Android. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`setClearBackgroundColor(true)`, 在 `android 4.4.2` 上无效,背景仍是白色的

JiangShuLiang opened this issue · comments

跪求解决办法,拜托拜托了!!!!感谢不尽!!!!
Uploading cgi-bin_mmwebwx-bin_webwxgetmsgimg_&MsgID=7898734967138859978&skey=@crypt_801aab47_6c67a647e7211bcc7e40c2d97907b279&mmweb_appid=wx_webfilehelper.jpg…

同样的代码, 在其他版本的系统上也有这个问题吗?

看你的截图, 似乎不用设置成透明颜色, 直接设置 AAChartModel 对象的背景色和整个大屏同色, 应该也行吧?

public class AAChartModel {
    ...
    public Object backgroundColor; //图表背景色
    ...
    public AAChart backgroundColor(Object prop) {
        backgroundColor = prop;
        return this;
    }
    ...
}

看你的截图, 似乎不用设置成透明颜色, 直接设置 AAChartModel 对象的背景色和整个大屏同色, 应该也行吧?

public class AAChartModel {
    ...
    public Object backgroundColor; //图表背景色
    ...
    public AAChart backgroundColor(Object prop) {
        backgroundColor = prop;
        return this;
    }
    ...
}

需要设成透明色的唉,因为整个背景是个地图(只是截图里没显示出来)。这个backgroundColor好像不支持透明色,我设成“#00000000”最终显示出来是白色底的

同样的代码, 在其他版本的系统上也有这个问题吗?

不会,在模拟器,手机,电视上都安装过,都正常。唯独这个机顶盒里安装不行

这个backgroundColor好像不支持透明色,我设成“#00000000”最终显示出来是白色底的

AAChartView 是继承自 WebView 的, 这个 backgroundColor 设置是的绘制图表的 <div> 标签的背景色的.

    public void setIsClearBackgroundColor(Boolean isClearBackgroundColor) {
        this.isClearBackgroundColor = isClearBackgroundColor;
        if (this.isClearBackgroundColor) {
            this.setBackgroundColor(0);
            this.getBackground().setAlpha(0);
        } else {
            this.setBackgroundColor(1);
            this.getBackground().setAlpha(255);
        }
    }

从上面的代码可以看出, setClearBackgroundColor 才是用来设置 WebView 自身为透明色的.

所以 AAChartView 的内部实现里有这段代码

 private void configureChartOptionsAndDrawChart(AAOptions chartOptions) {
        if (isClearBackgroundColor) {
            chartOptions.chart.backgroundColor("rgba(0,0,0,0)"); //这里就是为了避免开发者忘了设置 `<div>` 的透明度
        }

        Gson gson = new Gson();
        String aaOptionsJsonStr = gson.toJson(chartOptions);
        this.optionsJson = aaOptionsJsonStr;
        String javaScriptStr = "loadTheHighChartView('"
                + aaOptionsJsonStr + "','"
                + this.contentWidth + "','"
                + this.contentHeight + "')";
        this.safeEvaluateJavaScriptString(javaScriptStr);
    }

其中

        if (isClearBackgroundColor) {
            chartOptions.chart.backgroundColor("rgba(0,0,0,0)"); //这里就是为了避免开发者忘了设置 `<div>` 的透明度
        }

这段代码, 就是为了避免开发者想要 AAChartView 为透明色, 但是只设置了 setClearBackgroundColor(true) , 而忘了设置 <div> 的透明度.

综上所述, 想要设置 AAChartView 为透明色, 需要同时保证 WebView 自身和绘制图表的 <div> 都是透明色.

同样的代码, 在其他版本的系统上也有这个问题吗?

不会,在模拟器,手机,电视上都安装过,都正常。唯独这个机顶盒里安装不行

所以这个估计是这个 Android 版本系统自身的 bug, 参考:

这里的解决方案, 在 android 4.4.2 上为 AAChartView 额外补充这段代码:

aaChartView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

这是为了关闭 WebView 的硬件加速功能,因为在某些情况下硬件加速会导致背景不透明.

⚠️注意:关闭硬件加速可能会影响性能,因此仅在必须时才禁用它(你这里应该只要确保系统版本为android 4.4.2时, 添加了这段代码即可).

感谢作者!这么详细的解答是我在gayhub上头一次遇到了,真心大写加粗的感谢!!!我这就去试试看!