mpandroidchart 我想获得第三个值
mpandroidchart I want to get 3rd value
我正在使用 mpandroidchart,但现在遇到问题
我像这样在数组中设置了 3 个值
(索引、值和另一个值)
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
但我找不到路
如何获取h值?
感谢阅读
*已编辑 *
enter image description here
这是我要制作的图片
* 已编辑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拉坎
你建议像上面的代码,但是有一些问题。
数组列表颜色;
-> “变量 'color' 可能尚未初始化
color.add(context.getResources().getColor(R.color.colorPrimary)
-> 无法解析符号 'context'
ArrayList 数据集 = new ArrayList<>(); //这是我的代码
dataSets.setColors(颜色);
-> 我的数据集中没有 setColors
这些问题是什么?
您需要创建:
ArrayList<Integer> colors = new ArrayList<>();
之后,您需要为要显示的颜色的每个条目添加值,您需要将代码修改为:
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));
}
完成颜色数组列表后,您可以将颜色设置为:
dataSet.setColors(color);
我正在使用 mpandroidchart,但现在遇到问题
我像这样在数组中设置了 3 个值 (索引、值和另一个值)
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
但我找不到路
如何获取h值?
感谢阅读
*已编辑 * enter image description here
这是我要制作的图片
* 已编辑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拉坎 你建议像上面的代码,但是有一些问题。
数组列表颜色; -> “变量 'color' 可能尚未初始化
color.add(context.getResources().getColor(R.color.colorPrimary) -> 无法解析符号 'context'
ArrayList 数据集 = new ArrayList<>(); //这是我的代码 dataSets.setColors(颜色); -> 我的数据集中没有 setColors
这些问题是什么?
您需要创建:
ArrayList<Integer> colors = new ArrayList<>();
之后,您需要为要显示的颜色的每个条目添加值,您需要将代码修改为:
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));
}
完成颜色数组列表后,您可以将颜色设置为:
dataSet.setColors(color);