Today, to record what BarChart (bar chart) is simple to use!
Note: I use the version MPAndroidChart-v3.0.3 (Should have some way to update a different version, can leave a message in the comments area, do everything I can to help you solve!)
Details --LineChart line chart MPAndroidChart use of (a) ( simple to use)
in detail using the line graph MPAndroidChart --LineChart (b) (landscaping detail)
This article will talk about how simply draw bar (there is a little bit small landscaping)
First on renderings:
XML
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="300dp">
</com.github.mikephil.charting.charts.BarChart>
Java
public class BarChartActivity extends AppCompatActivity {
private BarChart bar;
List<BarEntry>list=new ArrayList<>();//实例化一个List用来存储数据
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bar_chart);
bar = (BarChart) findViewById(R.id.bar);
//添加数据
list.add(new BarEntry(1,3));
list.add(new BarEntry(2,8));
list.add(new BarEntry(3,6));
list.add(new BarEntry(4,9));
BarDataSet barDataSet=new BarDataSet(list,"语文");
BarData barData=new BarData(barDataSet);
bar.setData(barData);
bar.getDescription().setEnabled(false);//隐藏右下角英文
bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);//X轴的位置 默认为上面
bar.getAxisRight().setEnabled(false);//隐藏右侧Y轴 默认是左右两侧都有Y轴
}
}