Further from @Ben's answer, if you are creating BarChart, and the time span of the bar is like an hour or a day, and you are supplying with millisecond or second data, you will end up getting the bars too thin to be visible. This is a bug posted in 2017 (https://github.com/PhilJay/MPAndroidChart/issues/2892) and remains unresolved to date unfortunately.
A workaround was proposed and it is to convert the millisecond values into your time span of the bar before setting then into BarEntry. My time span is a day, so
I have the formatter as:
static class BarChartXAxisValueFormatter extends IndexAxisValueFormatter {
@Override
public String getFormattedValue(float value) {
// Convert float value to date string
// Convert from days back to milliseconds to format time to show to the user
long emissionsMilliSince1970Time = TimeUnit.DAYS.toMillis((long)value);
// Show time in local version
Date timeMilliseconds = new Date(emissionsMilliSince1970Time);
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("MM-dd");
return dateTimeFormat.format(timeMilliseconds);
}
}
And I set the X axis with:
xAxis.setValueFormatter(new BarChartXAxisValueFormatter());
Then when setting the data to the bar, I have
new BarEntry(TimeUnit.MILLISECONDS.toDays((long)valX), valY)
.