我正在使用android的MPCHART,但想在X轴上显示日期值,但是BarEntry承担浮点值,如何解析日期以在BarEntry中输入值或向x的条形图添加值的任何替代方法和y轴。
buildSchema
// orderXAxis.setValueFormatter(new DayXAxisFormatter());
private void grossChartSetup(ArrayList<BarEntry> grosssalesamountToday) {
grossChart.setMarker(iMarker);
grossChart.setDrawBarShadow(false);
grossChart.setMaxVisibleValueCount(24);
grossChart.setPinchZoom(false);
grossChart.setEnabled(false);
grossChart.setDrawBarShadow(false);
grossChart.setDoubleTapToZoomEnabled(false);
grossChart.getDescription().setEnabled(false);
grossChart.setHighlightFullBarEnabled(false);
grossChart.setOnChartGestureListener(this);
BarDataSet orderDataSet1 = new BarDataSet(grosssalesamountToday, "Actual");
orderDataSet1.setColor(mContext.getResources().getColor(R.color.darkCyan));
BarData orderdata = new BarData(orderDataSet1);
orderdata.setValueFormatter(new LargeValueFormatter());
grossChart.setData(orderdata);
float barWidth = 0.1f;
grossChart.getBarData().setBarWidth(barWidth);
XAxis orderXAxis = orderChart.getXAxis();
orderXAxis.setDrawGridLines(false);
orderXAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
答案 0 :(得分:0)
您必须像下面那样创建自己的值格式化程序
public class MyYAxisValueFormatter implements IValueFormatter {
public MyYAxisValueFormatter() {
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
// "value" represents the position of the label on the axis (x or y)
// value => date in MiliSecond
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
return dateFormat.format(value)
}
}
然后您可以将其设置为dataFormatter,如下所示
dataSet.setValueFormatter(new MyYAxisValueFormatter())