hellocharts-android 简单使用
来源:互联网 发布:js 资源加载异常捕获 编辑:程序博客网 时间:2024/06/11 17:49
这次介绍一个超级好用的图标库,hellocharts-android-master,大家先预览一下这个库的效果
github原链接HelloCharts-Android-master
这个库的动画及手势效果极佳,用户体验也很棒,但是!
他的坐标轴似乎不能定义。基本只能显示为固定的内容。
AxisValueFormatter接口只定义了两个int方法,根本没有给出String的写法,如果有哪位大神有办法能给出string的写法请留言,我先谢谢了。
public interface AxisValueFormatter { /** * Formats AxisValue for manual(custom) axis. Result is stored in (output) formattedValue array. Method * returns number of chars of formatted value. The formatted value starts at index [formattedValue.length - * charsNumber] and ends at index [formattedValue.length-1]. */ public int formatValueForManualAxis(char[] formattedValue, AxisValue axisValue); /** * Used only for auto-generated axes. If you are not going to use your implementation for aut-generated axes you can * skip implementation of this method and just return 0. SFormats values with given number of digits after * decimal separator. Result is stored in given array. Method returns number of chars for formatted value. The * formatted value starts at index [formattedValue.length - charsNumber] and ends at index [formattedValue * .length-1]. */ public int formatValueForAutoGeneratedAxis(char[] formattedValue, float value, int autoDecimalDigits);}
闲话少许,请看小小的demo,希望能给困惑绘图的小伙伴们些许灵感。
先上个小实例:
简单的折线图
package com.leo.test.activity;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import com.leo.test.R;import java.util.ArrayList;import java.util.List;import lecho.lib.hellocharts.model.Axis;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;/** * @Function * @Author Leo * @CreateTime 2015/12/21 0021 */public class LineChartActivity extends AppCompatActivity { private LineChartView line_chart_view; private LineChartData data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_line_chart); line_chart_view = (LineChartView) findViewById(R.id.line_chart_view);<span style="white-space:pre"></span> List<Line> lines = initLine(); data = initData(lines); line_chart_view.setLineChartData(data); Viewport viewport = initViewPort(); line_chart_view.setMaximumViewport(viewport); line_chart_view.setCurrentViewport(viewport); } /** * 设置4个边距 */ private Viewport initViewPort() { Viewport viewport = new Viewport(); viewport.top = 100; viewport.bottom = 0; viewport.left = 0; viewport.right = 90; return viewport; } /** * 初始化线属性 * * @return */ private List<Line> initLine() { List<Line> lineList = new ArrayList<>(); List<PointValue> pointValueList = new ArrayList<>(); PointValue pointValue1 = new PointValue(10,30); pointValueList.add(pointValue1); PointValue pointValue2 = new PointValue(20,20); pointValueList.add(pointValue2); PointValue pointValue3 = new PointValue(30,70); pointValueList.add(pointValue3); PointValue pointValue4 = new PointValue(40,69); pointValueList.add(pointValue4); PointValue pointValue5 = new PointValue(50,64); pointValueList.add(pointValue5); PointValue pointValue6 = new PointValue(60,31); pointValueList.add(pointValue6); PointValue pointValue7 = new PointValue(70,22); pointValueList.add(pointValue7); PointValue pointValue8 = new PointValue(80,100); pointValueList.add(pointValue8); Line line = new Line(pointValueList); line.setColor(getResources().getColor(R.color.colorAccent)); line.setShape(ValueShape.CIRCLE); lineList.add(line); return lineList; } /** * 初始化数据 * * @return */ private LineChartData initData(List<Line> lines) { LineChartData data = new LineChartData(lines); //初始化轴 Axis axisX = new Axis(); Axis axisY = new Axis().setHasLines(true); axisX.setName("时间"); //前加字符// axisX.setFormatter(new SimpleAxisValueFormatter().setPrependedText("aaaa".toCharArray())); //后加字符// axisX.setFormatter(new SimpleAxisValueFormatter().setAppendedText("aaaa".toCharArray()));// axisX.setFormatter(new SimpleAxisValueFormatter()); axisY.setName("销量"); //设置轴 data.setAxisYLeft(axisY); data.setAxisXBottom(axisX); //设置负值 设置为负无穷 默认为0// data.setBaseValue(Float.NEGATIVE_INFINITY); return data; }}下面是xml文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" android:orientation="vertical"> <lecho.lib.hellocharts.view.LineChartView android:background="#123456" android:id="@+id/line_chart_view" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
附上官方demo的CSDN下载地址,送给那些github上不去的童鞋官方demo
0 0
- hellocharts-android 简单使用
- Android开源图表控件hellocharts-android简单使用
- hellocharts-android图表库使用详解
- hellocharts的简单用法
- HelloCharts的简单Demo
- Hellocharts超简单源码
- hellocharts-android-Android图表开源库的使用(一)
- hellocharts-android-Android图表开源库的使用(二)
- hellocharts-android-Android图表开源库的使用(一)
- hellocharts-android-Android图表开源库的使用(二)
- 关于开源图表hellocharts-android的一些使用心得
- Android 使用hellocharts实现初始化x轴滑动
- android hellocharts 环形图
- Android 统计框架hellocharts
- android helloCharts 柱状图小结
- HelloCharts 之饼状图使用
- hellocharts使用流程
- HelloCharts
- java取html标签
- 《数字图像处理》笔记
- [leetcode] 52. N-Queens II 解题报告
- JfreeChar 画横向柱状图
- 2014年android应用开发岗面试题总结
- hellocharts-android 简单使用
- dubbo/dubbox(一)源码编译
- 关于jquery的rorate插件在IE7,8下不转动的问题
- unity5 资源管理和打包
- 基本排序_希尔排序_Java实现
- Oracle中过程/函数返回结果集
- Oracle优化器
- 【实践】express搭建nodeJS中间层(一)
- CentOS 6.3以上下配置LVM(逻辑卷管理)