华域联盟 Andriod Android HelloChart开源库图表之折线图的实例代码

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开源库图表之折线图的实例代码

转载请保留出处和原文链接:https://www.cnhackhy.com/106621.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

Android MPAndroidChart开源图表库之饼状图的代码

Android自定义View实现渐变色进度条

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们