Android HelloChart开源库图表之折线图的实例代码

前面我们介绍了开源图表库MPAndroidChart,请参考:

Android MPAndroidChart开源库图表之折线图的实例代码

我们今天介绍的将是一个更为优秀的图表库,比MPAndroidChart性能更好,功能更完善,UI风格更美观,坐标轴更精细。

支持缩放、滑动以及平移。Zoom(pinch to zoom, double tap zoom), scroll and fling

支持自定义坐标轴(比如坐标轴位置:上下左右内部),支持自动生成坐标轴。Custom and auto-generated axes(top, bottom, left, right, inside)

动画(Animations)

支持预览,即在chart下面会有一个坐标密度更细的附属chart,当选中附属chart的某一区域,附属chart上面的chart会显示选中区域的更详细情况。

GitHub地址

下面主要实现折线图:

1.从上面的地址中下载最新hellocharts-library-1.5.3.jar包, 然后copy到项目的libs中

2. 定义xml文件

3. 显示折线图的部分逻辑如下:

for (int i = 0; i < 10 ; i++) {

mPointValues.add(new PointValue(i, new Random().nextInt(10)));

mAxisValues.add(new AxisValue(i).setLabel(i)); //为每个对应的i设置相应的label(显示在X轴)

}

Line line = new Line(mPointValues).setColor(BLUE).setCubic(false);

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(BLUE);

axisX.setName("采集时间");

axisX.setMaxLabelChars(10);

axisX.setValues(mAxisValues);

data.setAxisXBottom(axisX);

Axis axisY = new Axis(); //Y轴

axisY.setMaxLabelChars(7); //默认是3,只能看最后三个数字

data.setAxisYLeft(axisY);

//设置行为属性,支持缩放、滑动以及平移

mLineChartView.setInteractive(true);

mLineChartView.setZoomType(ZoomType.HORIZONTAL);

mLineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

mLineChartView.setLineChartData(data);

mLineChartView.setVisibility(View.VISIBLE);

上文所表述的全部内容是Android HelloChart开源库图表之折线图的实例代码,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。

以上是 Android HelloChart开源库图表之折线图的实例代码 的全部内容, 来源链接: utcz.com/p/240516.html

回到顶部