我试图在x轴上显示日期和时间,但它不是get.also它将x轴返回为空白。
我的代码: -
ArrayList<Entry> entries = new ArrayList<>();
entries.add(new Entry(1479249799770L, 98.3f));
entries.add(new Entry(1479249799771L, 58.3f));
entries.add(new Entry(1479249799772L, 78.3f));
entries.add(new Entry(1479249799773L, 48.3f));
entries.add(new Entry(1479249799774L, 68.3f));
LineDataSet set1;
// create a dataset and give it a type
set1 = new LineDataSet(entries, "DataSet 1");
set1.setFillAlpha(110);
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);
set1.setLineWidth(1f);
set1.setCircleRadius(3f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(9f);
set1.setDrawFilled(false);
mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
mChart.getXAxis().setValueFormatter(new MyXAxisValueFormatter());
mChart.setViewPortOffsets(60, 0, 50, 60);
//ArrayList<ILineDataSet> dataSets = new ArrayList<>();
//dataSets.add(set1);
//LineData data = new LineData(dataSets);
//LineDataSet set = new LineDataSet(null, null);
LineData data = new LineData();
data.addDataSet(set1);
mChart.setData(data);
还添加了MyAxisValueFormatter类来格式化x轴值: -
public class MyXAxisValueFormatter implements IAxisValueFormatter {
@Override
public String getFormattedValue(float value, AxisBase axis) {
// Simple version. You should use a DateFormatter to specify how you want to textually represent your date.
Log.d("",""+value);
Date date = new Date((long) value);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dateString = formatter.format(date);
return dateString;
}
@Override
public int getDecimalDigits() {
return 0;
}
}
Thanks.Suggest me在上面的代码中我做错了什么?
答案 0 :(得分:0)
这些是我的新条目x值,即时间戳条目错误。 我在下面尝试并获得完美的图表。
entries.add(new Entry(1451660400L, 98.3f));
entries.add(new Entry(1451685600L, 58.3f));
entries.add(new Entry(1451721600L, 78.3f));
entries.add(new Entry(1451743200L, 48.3f));
entries.add(new Entry(1451761200L, 68.3f));
并将x值标签作为日期。