在网上搜了很多。该有的属性介绍我相信别人的会更全。但我想要显示小数的值。说句实话没找到。通过条形图的代码中API猜想的,一试,果然好用。想要显示小数的。就一句话LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(2);line.setFormatter(chartValueFormatter);//显示小数点就一句话,查了半天。多的不说了tiedaimpublic class SensorChartsActivity extends AppCompatActivity implements View.OnClickListener{ PRivate LineChartView line_chart; Float[] timePoint= {12.55f,12.55f,-10.0f,9.05f}; private List<PointValue> mPointValues = new ArrayList<PointValue>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sensor_charts); getSupportActionBar().hide(); line_chart=(LineChartView)findViewById(R.id.line_chart); initLineChart(); } private void initLineChart(){ for(int i=0;i<timePoint.length;i++){ mPointValues.add(new PointValue(i,timePoint[i].floatValue())); } Line line = new Line(mPointValues).setColor(Color.parseColor("#47C01D")); List<Line> lines = new ArrayList<Line>(); LineChartValueFormatter chartValueFormatter = new SimpleLineChartValueFormatter(2); line.setFormatter(chartValueFormatter);//显示小数点 line.setHasLabels(true);//曲线的数据坐标是否加上备注 line.setShape(ValueShape.CIRCLE);//端点显示圆点 line.setCubic(false);//曲线是否平滑 line.setFilled(true);//是否填充曲线的面积 line.setHasLabelsOnlyForSelected(false);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效) line.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示 line.setHaspoints(true);//是否显示圆点 如果为false 则没有原点只有点显示 lines.add(line); LineChartData data = new LineChartData(); data.setLines(lines); data.setBaseValue(Float.NEGATIVE_INFINITY);// X轴,字体斜,字体颜色,字体大小,最多几个值 Axis axisX = new Axis(); axisX.setName("时间(h)"); axisX.setTextSize(14); axisX.setTextColor(Color.BLACK); data.setAxisXBottom(axisX); axisX.setHasLines(true); Axis axisY = new Axis(); axisY.setName("温度(℃)"); axisY.setTextSize(14); axisY.setTextColor(Color.BLACK); axisY.setHasLines(true); data.setAxisYLeft(axisY); line_chart.setInteractive(true); line_chart.setZoomType(ZoomType.HORIZONTAL); line_chart.setMaxZoom((float) 3); line_chart.setLineChartData(data); line_chart.setVisibility(View.VISIBLE);}
}
这就是完成的样子了
新闻热点
疑难解答