Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用MPAndroidChart库更改图表背景?_Android_Charts_Mpandroidchart - Fatal编程技术网

如何使用MPAndroidChart库更改图表背景?

如何使用MPAndroidChart库更改图表背景?,android,charts,mpandroidchart,Android,Charts,Mpandroidchart,我正在使用这个神奇的图书馆。它就像一个符咒,除了当我试图改变巴达塔的背景颜色。默认颜色为白色,我想将其更改为透明 我试过这个: Paint p1 = mChart.getPaint(Chart.PAINT_GRID_BACKGROUND); p1.setColor(Color.RED); 这是: <com.github.mikephil.charting.charts.BarChart android:id="@+id/chart1" android:la

我正在使用这个神奇的图书馆。它就像一个符咒,除了当我试图改变巴达塔的背景颜色。默认颜色为白色,我想将其更改为透明

我试过这个:

Paint p1 = mChart.getPaint(Chart.PAINT_GRID_BACKGROUND);
p1.setColor(Color.RED);
这是:

<com.github.mikephil.charting.charts.BarChart
        android:id="@+id/chart1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"/>

。。。但这似乎不起作用

有什么想法吗


谢谢=)

所以,经过一些研究,我发现这还不可能:

希望这很快成为可能!=)

由于,默认情况下,
图表的背景是透明的。这意味着,背景(图表背景、其他
视图
等)中未被绘制到
图表
中的数据覆盖的所有内容都将可见

如果您想要更改背景(颜色,或者可能是可绘制的),您可以通过更改图表背景来完成

  • in.xml(
    android:background=“…”
  • 通过调用
    setBackgroundColor(…)
    setBackgroundResource(…)

另一种方法是更改包含
图表的父布局的背景

更改背景颜色的代码:

chart.setBackgroundColor(Color.TRANSPARENT); //set whatever color you prefer
chart.setDrawGridBackground(false);// this is a must 

如果你想改变整个屏幕的背景色

 Barchart chart;
 chart.setBackgroundColor(Color.rgb(0, 0, 0));//Set as a black
 chart.setDrawGridBackground(false);//set this to true to draw the grid background, false if not

很高兴为您提供帮助,谢谢

我正在测试您的新版本,透明的背景效果非常好!谢谢again@Philipp我们只能为范围设置背景。As-30和低于红色-10低于黄色,10高于黄色,30高于红色