LineChart.setExtraOffsets空指针或者是LineChart.animateX空指针

先展示布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/chart_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textStyle="bold"
        android:gravity="center"
        android:textSize="30sp"/>

    <com.github.mikephil.charting.charts.LineChart
        android:id="@+id/chart"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

在使用LineChart的时候如果出现这类的报错:
LineChart报错01
先确定 LineChart 的 findViewById 是否正确:

mChart = (LineChart) view.findViewById(R.id.chart);

这个要和你的 LineChart 布局文件的 id 名匹配。

我是用 ViewPager 调用 LineChart,所以下面的LineChart代码都是在 fragment v4 的包里写的。
上面确认无误之后,还是没有解决上面的报错就看一下这两段代码:

public View onCreateView(LayoutInflater inflater, 
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.chart_item,container, false);
        initView(view);
        return view;
    }

在导入 LineChart 布局之后,一定要写 container 。

然后是第二行代码:

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ...
    }

要使用 onViewCreated 这个方法。

以上就是解决LineChart在设置 setExtraOffsets 方法和 animateX 时产生空指针的办法。

LineChart 设置 animate 这个的时候不是只有X轴,所以解决方法都是能用的。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花牌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值