码迷,mamicode.com
首页 > 其他好文 > 详细

HelloCharts开源图表库(一)之折线图

时间:2015-04-11 20:57:09      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:hellocharts

  • 之前我们介绍了开源图表库MPAndriodChart,请参考http://blog.csdn.net/shineflowers/article/details/44704723

  • 我们今天介绍的将是一个更为优秀的图表库,比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地址:

  • https://github.com/lecho/hellocharts-android

  • 下面主要实现折线图:

  • 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);


HelloCharts开源图表库(一)之折线图

标签:hellocharts

原文地址:http://blog.csdn.net/shineflowers/article/details/44998167

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!