mpandroidchart I want to get 3rd value

江枫思渺然 提交于 2019-12-11 15:32:21

问题


I am using mpandroidchart and i have a problem now

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

I want to get h values to use this h

but i cant' find the way

How can i get h value?

Thanks for reading

*Edited * enter image description here

This is the image i want to make

* Edited2 *

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

Dear M.Saad Lakhan You suggested like upper code, But there are some ploblems.

  1. ArrayList color; -> "variable 'color' might not have been initiallized

  2. color.add(context.getResources().getColor(R.color.colorPrimary) -> cannot resolve symbol 'context'

  3. ArrayList dataSets = new ArrayList<>(); //this is my code dataSets.setColors(color); -> there is no setColors in my datasets

What are these problem?


回答1:


You need to create:

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


来源:https://stackoverflow.com/questions/54977571/mpandroidchart-i-want-to-get-3rd-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!