一、今日学习内容
体温上报个人作业的第三阶段——体温统计地图可视化:折线图
package com.example.tiwen; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.ListView; import androidx.appcompat.app.AppCompatActivity; import org.litepal.LitePal; import java.util.ArrayList; import java.util.List; import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter; import lecho.lib.hellocharts.gesture.ZoomType; import lecho.lib.hellocharts.model.Axis; import lecho.lib.hellocharts.model.AxisValue; import lecho.lib.hellocharts.model.Line; import lecho.lib.hellocharts.model.LineChartData; import lecho.lib.hellocharts.model.PointValue; import lecho.lib.hellocharts.model.ValueShape; import lecho.lib.hellocharts.model.Viewport; import lecho.lib.hellocharts.view.LineChartView; public class ListActivity extends AppCompatActivity { private ListView listview; private List<TiWen> stepEntityList = new ArrayList<>(); private TiWen t; private LineChartView lineChart; private List<TiWen> list; String ID1; String[] date ; Float[] tiwen; private List<PointValue> mPointValues = new ArrayList<PointValue>(); private List<AxisValue> mAxisXValues = new ArrayList<AxisValue>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); List<Judge> judge= LitePal.findAll(Judge.class); for(Judge j:judge){ ID1=j.getID1(); } list= (List<TiWen>) LitePal.where("ID1 = ?",ID1).find(TiWen.class); initView(); date=new String[list.size()]; tiwen=new Float[list.size()]; for (int i=0;i<list.size();i++){ date[i]=list.get(i).getDate1(); tiwen[i]=Float.parseFloat(list.get(i).getTiwen()); } getAxisXLables(); getAxisPoints(); initLineChart(); } private void initLineChart(){ Line line = new Line(mPointValues).setColor(Color.parseColor("#FFCD41")); List<Line> lines = new ArrayList<Line>(); line.setShape(ValueShape.CIRCLE); //折线图上每个数据点的形状,这里是圆形 line.setCubic(false); line.setFilled(false); line.setHasLabels(true); line.setHasLines(true); line.setHasPoints(true); line.setFormatter(new SimpleLineChartValueFormatter(1));//设置显示小数点 line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效) lines.add(line); LineChartData data = new LineChartData(); data.setLines(lines); //坐标轴 Axis axisX = new Axis(); axisX.setHasTiltedLabels(true); axisX.setTextColor(Color.parseColor("#D6D6D9"));//设置字体颜色 axisX.setTextSize(8);//设置字体大小 axisX.setMaxLabelChars(8);//最多几个X轴坐标 axisX.setValues(mAxisXValues); data.setAxisXBottom(axisX); axisX.setHasLines(true); Axis axisY = new Axis(); axisY.setName(""); axisY.setTextSize(15); data.setAxisYLeft(axisY); //设置行为属性,缩放、滑动、平移 lineChart.setInteractive(true); lineChart.setZoomType(ZoomType.HORIZONTAL); lineChart.setMaxZoom((float) 3); lineChart.setLineChartData(data); lineChart.setVisibility(View.VISIBLE); //设置X轴数据的显示个数(x轴0-7个数据) Viewport v = new Viewport(lineChart.getMaximumViewport()); v.left = 0; v.right= 14; lineChart.setCurrentViewport(v); } private void initView() { listview=(ListView) findViewById(R.id.listview); lineChart = (LineChartView)findViewById(R.id.line_chart); } private void getAxisXLables(){ for (int i = 0; i < date.length; i++) { mAxisXValues.add(new AxisValue(i).setLabel(date[i])); } } private void getAxisPoints(){ for (int i = 0; i < tiwen.length; i++) { mPointValues.add(new PointValue(i, tiwen[i])); } } }
效果图:
二、遇到的问题
开始对于折线图上的点,点击之后不能显示具体温度、
三、明日计划
明天完成地图可视化