最近做的项目需要用到动态折线图,因为知道一个很好的库MPAndroidChart,所以就想用它来完成,下面是我通过官方Demo制作的一个Demo。
首先初始化折线图
private void initChart() {
// enable description text
mChart.getDescription().setEnabled(false);
// enable touch gestures
mChart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
// set an alternative background color
mChart.setBackgroundColor(Color.WHITE);
LineData data = new LineData();
data.setValueTextColor(Color.WHITE);
// add empty data
mChart.setData(data);
// get the legend (only possible after setting data)
Legend l = mChart.getLegend();
// modify the legend ...
l.setForm(Legend.LegendForm.LINE);
l.setTypeface(mTfLight);
l.setTextColor(Color.WHITE);
l.setEnabled(false);
XAxis xl = mChart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
xl.setDrawLabels(false);
xl.setGranularity(1f);

本文介绍了使用MPAndroidChart库创建动态折线图的步骤,包括初始化折线图和添加数据的过程。
最低0.47元/天 解锁文章
862





