如何使用MPAndroidChart库改变图表背景? [英] How to change chart background with MPAndroidChart library?

查看:607
本文介绍了如何使用MPAndroidChart库改变图表背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了惊人的图书馆 MPAndroidChart 。它的作用就像一个魅力,除非当我试图改变BarData的背景颜色。默认颜色为白色,我想将其更改为透明。

I'm using the amazing library MPAndroidChart. It works like a charm, except when I'm trying to change the background color of the BarData. Default color is white, and I want to change it to Transparent.

我尝试过:

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"/>

...但似乎无效。

任何想法?

谢谢=)

推荐答案

由于 版本v1.6.5 图表默认情况下为透明。意思是,在图表中绘制的数据不重叠的背景中的所有内容(图表背景,其他视图等) $ c>,将可见。

Since release v1.6.5, the background of the Chart is transparent by default. Meaning, that everything in the background (chart background, other Views, etc.) that is not overlayed by data drawn into the Chart, will be visible.

如果您想更改背景(颜色,或可能是drawable),您可以通过更改chart- / android:background =...

If you want to change the background (color, or maybe drawable), you can either do that by changing the chart-background


    <通过调用 setBackgroundColor(...) setBackgroundResource(...)
  • in .xml (android:background="...")
  • by calling setBackgroundColor(...) or setBackgroundResource(...)

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

Another way could be to change the background of the parent layout that contains the Chart.

这篇关于如何使用MPAndroidChart库改变图表背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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