android hellocharts 折线图 X轴传中文

xiaoxiao2021-02-28  15

主布局文件

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <lecho.lib.hellocharts.view.LineChartView        android:id="@+id/activity_charts_line_lcv"        android:layout_width="match_parent"        android:layout_height="match_parent" /></FrameLayout>

 

3,activity

package com.sonar.android.push.demo.getui.activities;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.os.Handler;import android.support.v4.widget.SwipeRefreshLayout;import android.widget.ArrayAdapter;import android.widget.ListView;import com.sonar.android.push.demo.getui.R;import java.util.ArrayList;import java.util.List;import java.util.Random;import lecho.lib.hellocharts.gesture.ContainerScrollType;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.view.LineChartView;/** * 使用HelloCharts图表开发库实现折线图 * Created by Administrator on 2016/10/26. */public class ChartsActivity extends Activity{    LineChartView lineChartView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.layout_activity_charts);        setView();        initView();    }    private void setView(){        lineChartView = (LineChartView)findViewById(R.id.activity_charts_line_lcv);    }    private void initView(){        List<PointValue> values = new ArrayList<PointValue>();        List<AxisValue> mAxisValues = new ArrayList<AxisValue>();        for (int i = 0; i < 10 ; i++) {            values.add(new PointValue(i, new Random().nextInt(5)));            mAxisValues.add(new AxisValue(i).setLabel(i+"")); //为每个对应的i设置相应的label(显示在X轴)        }        //In most cased you can call data model methods in builder-pattern-like manner.        Line line = new Line(values).setColor(Color.BLUE).setCubic(true);        List<Line> lines = new ArrayList<Line>();        lines.add(line);        LineChartData data = new LineChartData();        data.setLines(lines);        //坐标轴        Axis axisX = new Axis(); //X轴        axisX.setHasTiltedLabels(true);        axisX.setTextColor(Color.BLUE);        axisX.setName("采集时间");        axisX.setMaxLabelChars(10);        axisX.setValues(mAxisValues);        data.setAxisXBottom(axisX);        Axis axisY = new Axis();  //Y轴        axisY.setName("幅度");        axisY.setMaxLabelChars(7); //默认是3,只能看最后三个数字        data.setAxisYLeft(axisY);        lineChartView.setInteractive(true);        lineChartView.setZoomType(ZoomType.HORIZONTAL);        lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);        lineChartView.setLineChartData(data);    }

}

效果图:

转载请注明原文地址: https://www.6miu.com/read-1750399.html

最新回复(0)