mpandroidchart我想获得第三个值 [英] mpandroidchart I want to get 3rd value
问题描述
我正在使用mpandroidchart,现在遇到了问题
I am using mpandroidchart and i have a problem now
我像这样将3个值设置到数组中 (索引,值和另一个值)
I set 3 values into the array likes this (index, values, and another value)
ArrayList<Entry> value1 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
float y = (float) Math.random();
float h = (float) Math.random();
value1.add(new Entry(i, y, h));
}
我想获取h值以使用此h
I want to get h values to use this h
但是我找不到路
我如何获得h值?
感谢阅读
*已编辑* 在此处输入图片描述
这是我要制作的图像
*已编辑2 *
ArrayList<Integer> color;
ArrayList<Entry> value1 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
float y = (float) Math.random();
value1.add(new Entry(i, y));
if(y>10)
{
color.add(context.getResources().getColor(R.color.colorPrimary));
}
else
color.add(context.getResources().getColor(R.color.colorAccent));
}
dataSet.setColors(color);
尊敬的萨阿德·拉汉(M.Saad Lakhan) 您建议像上层代码一样,但是有一些问题.
Dear M.Saad Lakhan You suggested like upper code, But there are some ploblems.
-
ArrayList颜色; ->变量'颜色'可能尚未初始化
ArrayList color; -> "variable 'color' might not have been initiallized
color.add(context.getResources().getColor(R.color.colorPrimary) ->无法解析符号上下文"
color.add(context.getResources().getColor(R.color.colorPrimary) -> cannot resolve symbol 'context'
ArrayList dataSets = new ArrayList<>(); //这是我的代码 dataSets.setColors(color); ->我的数据集中没有setColors
ArrayList dataSets = new ArrayList<>(); //this is my code dataSets.setColors(color); -> there is no setColors in my datasets
这些问题是什么?
推荐答案
您需要创建:
ArrayList<Integer> colors = new ArrayList<>();
此后,您需要为每个条目添加要显示的颜色的值,您需要将代码修改为:
After that you need to add values for each entry which color you want to show, you need to modify your code as:
ArrayList<Entry> value1 = new ArrayList<>();
for (int i = 0; i < 10; i++)
{
float y = (float) Math.random();
value1.add(new Entry(i, y));
// add your condition here
if(y>10)
{
color.add(getContext().getResources().getColor(R.color.colorPrimary));
}
else
color.add(getContext().getResources().getColor(R.color.colorAccent));
}
完成颜色数组列表后,可以将颜色设置为:
When you complete your colors arraylist then you can set colors as:
dataSet.setColors(color);
这篇关于mpandroidchart我想获得第三个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!