android使用hellocharts框架画出类型与CSDN数据看板的折线图?

android使用hellocharts框架画出类型与CSDN数据看板的折线图?,第1张

概述android使用hellocharts框架画折线图第一步:导入依赖包第二步:配置xml文件第三步:activity代码(重点)1.先对整体有一个了解2.细说1.resetViewport方法2.generateValues方法3.generateData方法(`重点`)内容最多首先附上hellocharts框架地址,我也是通过下载那个demo进行理解性

androID使用hellocharts框架画折线图第一步:导入依赖包第二步:配置xml文件第三步:activity代码(重点)1.先对整体有一个了解2.细说1.resetViewport方法2.generateValues方法3.generateData方法(`重点`)内容最多

首先附上hellocharts框架地址,我也是通过下载那个demo进行理解性测试学习的,可能会有没有考虑到的地方,还请指出。如果想更深一步了解这个框架,可以下载Demo自己去学习一下。

废话少说,上效果图:


@H_502_45@

第一步:导入依赖包
implementation 'com.github.lecho:hellocharts-androID:v1.5.8'@H_419_54@第二步:配置xml文件

这里还是比较简单,没有什么好说的

<androIDx.constraintlayout.Widget.ConstraintLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".lineChartActivity" >    <lecho.lib.hellocharts.vIEw.lineChartVIEw        androID:ID="@+ID/chart"        androID:layout_wIDth="match_parent"        androID:layout_height="200dp"        androID:layout_marginBottom="100dp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_totopOf="parent"></lecho.lib.hellocharts.vIEw.lineChartVIEw></androIDx.constraintlayout.Widget.ConstraintLayout>@H_419_54@第三步:activity代码(重点)

首先附上所有代码,下面进行参数的详解:

package com.example.williamchart;import androID.graphics.color;import androID.os.Bundle;import androID.vIEw.LayoutInflater;import androID.vIEw.Menu;import androID.vIEw.MenuInflater;import androID.vIEw.MenuItem;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.Toast;import androIDx.appcompat.app.AppCompatActivity;import androIDx.fragment.app.Fragment;import java.util.ArrayList;import java.util.List;import lecho.lib.hellocharts.animation.ChartAnimationListener;import lecho.lib.hellocharts.gesture.ZoomType;import lecho.lib.hellocharts.Listener.lineChartOnValueSelectListener;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.model.ValueShape;import lecho.lib.hellocharts.model.VIEwport;import lecho.lib.hellocharts.util.ChartUtils;import lecho.lib.hellocharts.vIEw.Chart;import lecho.lib.hellocharts.vIEw.lineChartVIEw;public class lineChartActivity extends AppCompatActivity {    private lineChartVIEw chart;    private final int maxnumberOflines = 4;    private final int numberOfPoints = 6;    private final int number=60;    float[][] randomNumbersTab = new float[maxnumberOflines][numberOfPoints];    private ValueShape shape = ValueShape.CIRCLE;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_line_chart);        chart=findVIEwByID(R.ID.chart);        generateValues();        generateData();        resetVIEwport();    }    //设置y轴的值从left到number    private voID resetVIEwport() {        final VIEwport v = new VIEwport(chart.getMaximumVIEwport());        v.bottom = 0;        v.top = number;        v.left = 0;        v.right = numberOfPoints - 1;        chart.setMaximumVIEwport(v);        chart.setCurrentVIEwport(v);    }    private voID generateValues() {        for (int i = 0; i < maxnumberOflines; ++i) {            for (int j = 0; j < numberOfPoints; ++j) {                randomNumbersTab[i][j] = (float) Math.random() * number;            }        }    }    private voID generateData() {        List<line> lines = new ArrayList<line>();        List<AxisValue> axisXValues = new ArrayList<AxisValue>();        for (int i = 0; i <= numberOfPoints; i++)            axisXValues.add(i, new AxisValue(i).setLabel(i + "月"));        int numberOflines = 1;        for (int i = 0; i < numberOflines; ++i) {            List<PointValue> values = new ArrayList<PointValue>();            for (int j = 0; j < numberOfPoints; j++) {                values.add(new PointValue(j, randomNumbersTab[i][j]));            }            line line = new line(values);            line.setcolor(ChartUtils.pickcolor());    //设置颜色随机            line.setShape(shape);         //设置形状            line.setCubic(true);          //设置线为曲线,反之为折线            line.setFilled(true);          //设置填满            line.setHasLabels(true);    //显示便签            line.setHasLabelsOnlyForSelected(true);            line.setHaslines(true);            line.setHasPoints(true);            lines.add(line);        }        lineChartData data = new lineChartData(lines);        data.setAxisXBottom(new Axis(axisXValues).setHaslines(true).setTextcolor(color.BLACK).setname("日期").setHasTiltedLabels(true).setMaxLabelChars(4));        data.setAxisYleft(new Axis().setHaslines(true).setname("收入").setTextcolor(color.BLACK).setMaxLabelChars(2));        data.setBaseValue(float.NEGATIVE_INFINITY);        chart.setlineChartData(data);    }}@H_419_54@1.先对整体有一个了解

2.细说1.resetVIEwport方法

设置y轴的值从0到number,number我设置为60。

2.generateValues方法

生成0到60的随机数,maxnumberOflines设置折线数我设置为一条,numberOfPoints设置点的个数我设置为6

3.generateData方法(重点)内容最多

图解:



我考虑的可能不是很周到,可以多试一下,说不定可以了解到更多功能。

如果有时间的话,我将会说一下统计图,扇形图等图的实现等。

总结

以上是内存溢出为你收集整理的android使用hellocharts框架画出类型与CSDN数据看板的折线图?全部内容,希望文章能够帮你解决android使用hellocharts框架画出类型与CSDN数据看板的折线图?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1054077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存