[关闭]
@zifeng328573112 2021-03-17T11:15:56.000000Z 字数 2182 阅读 266

MPAndroidChart技术-开始 Getting Started(一)

一、使用

为了使用 LineChart, BarChart, ScatterChart, CandleStickChart, PieChart, BubbleChart or RadarChart ,要在.xml 文件定义:

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

然后在 Activity 或 Fragment 中拿到你定义的 chart:

  1. // in this example, a LineChart is initialized from xml
  2. LineChart chart = (LineChart) findViewById(R.id.chart);

使用 java 代码创建它(如果不是在布局文件中定义,需要将其加入你的布局):

  1. // programmatically create a LineChart
  2. LineChart chart = new LineChart(Context);
  3. // get a layout defined in xml
  4. RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativeLayout);
  5. rl.add(chart); // add the programmatically created chart

二、刷新

三、打印日志

四、基本chart风格

这里我们先定义一个LineChart范例:

  1. <!--折线图,layout的背景色为 #bdbdbd 灰-->
  2. <com.github.mikephil.charting.charts.LineChart
  3. android:id="@+id/line_chart"
  4. android:layout_width="match_parent"
  5. android:layout_height="300dp"
  6. android:background="#ffffff"
  7. android:layout_margin="16dp"/>

img18

下面是一些可以直接在 chart 上使用的设置 style 的方法:

五、其他章节索引

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注