1
我这个MPAndroid chart library只是有点失落。MPAndroidChart - 我怎样才能最好设置X轴值作为字符串/日期?
我开始初学者例如here,其中建议创建对象与getValueX()和getValueY()方法,你会再添加作为条目,像这样的数组/列表:
List<Entry> entries = new ArrayList<Entry>(); // entry list
for(ValueAndDateObject data : valueAndDateArrayList){
// valueAndDateArrayList is the list of my own data
//(objects with a String X-value, and a double Y-value)
entries.add(new Entry(data.getValueX(), data.getValueY())); //error here
}
有一个错误,因为Entry只需要(float x,float y)。很显然,我可以将double作为float来投射,但我需要x轴的日期不是浮动的。所以我做了一些更多的搜索,发现了很多关于它的Github问题,但是我似乎无法理解那些解决方案。大多数指向this in the docs之类的东西。我遇到的问题是我不明白这是如何应用于Entry(float x,float y)问题。我无法找到文档/解决方案何时/何地应用于Entry()。
所以,当我看到有关创建格式化,然后将其设置的例子,我不明白其中entries.add(新条目())的东西进来,请问该技术取代它呢?我不知何故将其传入?
供参考,这是我的完整的方法,前面提到的初学者例子后设计的。
public void updateUI(final ArrayList<ValueAndDateObject> valueAndDateArrayList){
List<Entry> entries = new ArrayList<Entry>();
for(ValueAndDateObject data : valueAndDateArrayList){
/** for the sake of the example, let's say there's only one
* ValueAndDataObject in the list and getValueX() returns "02-27-2016"
* and getValueY() returns 12,345.0
*/
entries.add(new Entry(data.getValueX(), data.getValueY())); //error obviously
}
// would I add the formatter somewhere in here? And what would I "add" it to?
LineDataSet dataSet = new LineDataSet(entries, "Label");
dataSet.setColor(Color.YELLOW);
dataSet.setValueTextColor(Color.BLACK);
LineData lineData = new LineData(dataSet);
lineChart.setData(lineData);
lineChart.invalidate();
}
从我可以告诉,我必须使自己的格式化程序类,我将关闭模拟在格式化文档链接字符串[]的例子。我的挂机位于“设置格式化程序”部分。只是不确定如何改变/与Entry(float x,float y)问题交互。