public LineDataSet(List yVals, String label) {
super(yVals, label);
// mCircleSize = Utils.convertDpToPixel(4f);
// mLineWidth = Utils.convertDpToPixel(1f);
mCircleColors = new ArrayList();
// default colors
// mColors.add(Color.rgb(192, 255, 140));
// mColors.add(Color.rgb(255, 247, 140));
mCircleColors.add(Color.rgb(140, 234, 255));
}
…
}
在构造函数中,很明显 LineDataSet
需要一个 Entry
的 ArrayList
参数,和一个 String
参数作为 图例 (Legend
)的 label
来描述 LineDataSet
。 此外, this label can be used to find the LineDataSet amongst other LineDataSet objects in the LineData object.
该 Entry
类型的 ArrayList
封装了图表所有的值。 Entry
相当一个容器,用来封装并保存“一对值”,and it’s position on the x-axis ( the index inside the ArrayList of String of the LineData object the value is mapped to
) :
public Entry(float val, int xIndex) { … }
3. 还是用之前的例子
以前面提到的(这两家公司一年的季度营收)为例:
- 总的数据包含和操作类似:
// 假设是为 LineChart 设置数据,数据操作顺序大概如下:
new Entry(float val, int xIndex);
new ArrayList();
new LineDataSet(ArrayList , “label”);
new ArrayList();
new LineData(List xVals, List dataSets));
chart.setData(LineData);
// 详细步骤继续往下看
- 首先,创建类型的列表Entry ,将保留您的值:
ArrayList valsComp1 = new ArrayList();
ArrayList valsComp2 = new ArrayList();
- 然后,给
lists
集合添加Entry
对象。
确保 Entry
对象包含的 index 都是正确的 (对于x轴来说)。
Entry c1e1 = new Entry(100.000f, 0); // 0 == quarter 1
valsComp1.add(c1e1);
Entry c1e2 = new Entry(50.000f, 1); // 1 == quarter 2 …
valsComp1.add(c1e2);
// and so on …
Entry c2e1 = new Entry(120.000f, 0); // 0 == quarter 1
valsComp2.add(c2e1);
Entry c2e2 = new Entry(110.000f, 1); // 1 == quarter 2 …
valsComp2.add(c2e2);
//…
- 现在,有了
Entry
对象的lists
集合,再创建LineDataSet
对象:
LineDataSet setComp1 = new LineDataSet(valsComp1, “Company 1”);
setComp1.setAxisDependency(AxisDependency.LEFT);
LineDataSet setComp2 = new LineDataSet(valsComp2, “Company 2”);
setComp2.setAxisDependency(AxisDependency.LEFT);
通过调用 setAxisDependency(...)
使得 DataSet
对应指定轴,进行绘制。
- 通过
DataSets
集合和x-axis entries
集合,来创建我们的ChartData
对象:
// public LineData(List xVals, List dataSets) {
// super(xVals, dataSets);
// }
ArrayList dataSets = new ArrayList();
dataSets.add(setComp1);
dataSets.add(setComp2);
ArrayList xVals = new ArrayList();
xVals.add(“1.Q”); xVals.add(“2.Q”); xVals.add(“3.Q”); xVals.add(“4.Q”);
LineData data = new LineData(xVals, dataSets);
mLineChart.setData(data);
mLineChart.invalidate(); // refresh
- 调用
invalidate()
后图表被刷新,所提供的数据重新绘制。
三、设置颜色
1. ColorTemplate 类简介
- Class that holds predefined color integer arrays (e.g. ColorTemplate.VORDIPLOM_COLORS) and convenience methods for loading colors from resources.
该类封装有 预定义的颜色整数数组(例如 ColorTemplate.VORDIPLOM_COLORS
)和便利的从资源加载颜色的方法。
ColorTemplate
类的源码
public class ColorTemplate {
/**
- an “invalid” color that indicates that no color is set
*/
public static final int COLOR_NONE = -1;
/**
-
this “color” is used for the Legend creation and indicates that the next
-
form should be skipped
*/
public static final int COLOR_SKIP = -2;
/**
-
THE COLOR THEMES ARE PREDEFINED (predefined color integer arrays), FEEL
-
FREE TO CREATE YOUR OWN WITH AS MANY DIFFERENT COLORS AS YOU WANT
*/
public static final int[] LIBERTY_COLORS = {
Color.rgb(207, 248, 246), Color.rgb(148, 212, 212), Color.rgb(136, 180, 187),
Color.rgb(118, 174, 175), Color.rgb(42, 109, 130)
};
public static final int[] JOYFUL_COLORS = {
Color.rgb(217, 80, 138), Color.rgb(254, 149, 7), Color.rgb(254, 247, 120),
Color.rgb(106, 167, 134), Color.rgb(53, 194, 209)
};
public static final int[] PASTEL_COLORS = {
Color.rgb(64, 89, 128), Color.rgb(149, 165, 124), Color.rgb(217, 184, 162),
Color.rgb(191, 134, 134), Color.rgb(179, 48, 80)
};
public static final int[] COLORFUL_COLORS = {
Color.rgb(193, 37, 82), Color.rgb(255, 102, 0), Color.rgb(245, 199, 0),
Color.rgb(106, 150, 31), Color.rgb(179, 100, 53)
};
public static final int[] VORDIPLOM_COLORS = {
Color.rgb(192, 255, 140), Color.rgb(255, 247, 140), Color.rgb(255, 208, 140),
Color.rgb(140, 234, 255), Color.rgb(255, 140, 157)
};
/**
-
Returns the Android ICS holo blue light color.
-
@return
*/
public static int getHoloBlue() {
return Color.rgb(51, 181, 229);
}
/**
-
turn an array of resource-colors (contains resource-id integers) into an
-
array list of actual color integers
-
@param r
-
@param colors an integer array of resource id’s of colors
-
@return
*/
public static List createColors(Resources r, int[] colors) {
List result = new ArrayList();
for (int i : colors) {
result.add(r.getColor(i));
}
return result;
}
/**
-
Turns an array of colors (integer color values) into an ArrayList of
-
colors.
-
@param colors
-
@return
*/
public static List createColors(int[] colors) {
List result = new ArrayList();
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
分享读者
作者2013年java转到Android开发,在小厂待过,也去过华为,OPPO等大厂待过,18年四月份进了阿里一直到现在。
被人面试过,也面试过很多人。深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长,而且极易碰到天花板技术停滞不前!
我们整理了一份阿里P7级别的Android架构师全套学习资料,特别适合有3-5年以上经验的小伙伴深入学习提升。
主要包括阿里,以及字节跳动,腾讯,华为,小米,等一线互联网公司主流架构技术。如果你有需要,尽管拿走好了。
35岁中年危机大多是因为被短期的利益牵着走,过早压榨掉了价值,如果能一开始就树立一个正确的长远的职业规划。35岁后的你只会比周围的人更值钱。
)]
分享读者
作者2013年java转到Android开发,在小厂待过,也去过华为,OPPO等大厂待过,18年四月份进了阿里一直到现在。
被人面试过,也面试过很多人。深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长,而且极易碰到天花板技术停滞不前!
我们整理了一份阿里P7级别的Android架构师全套学习资料,特别适合有3-5年以上经验的小伙伴深入学习提升。
主要包括阿里,以及字节跳动,腾讯,华为,小米,等一线互联网公司主流架构技术。如果你有需要,尽管拿走好了。
[外链图片转存中…(img-AEclbOkC-1711780871667)]
35岁中年危机大多是因为被短期的利益牵着走,过早压榨掉了价值,如果能一开始就树立一个正确的长远的职业规划。35岁后的你只会比周围的人更值钱。