问题
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.
ArrayList color; -> "variable 'color' might not have been initiallized
color.add(context.getResources().getColor(R.color.colorPrimary) -> cannot resolve symbol 'context'
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