enter image description herehave a look bars are not displaying properlyI have a dataset which has around 10 x-axis labels. My Bar chart is not displaying all the labels in my x-axis.
Only Displaying First and last Labels.I have to display all the 10 x-axis Labels In my bar chart.
Below one is reference for the imagewhen I do pinchzoom with fingers that time I can able to see the remaing Labels.But bars not displaying properly
private void setData_chart(int count, float range) {
float barWidth = 10f;
float spaceForBar = 12f;
float groupSpace = 0.06f;
float barSpace = 0.02f;
ArrayList<BarEntry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range);
values.add(new BarEntry(i * spaceForBar, val,
getResources().getDrawable(R.drawable.ic_launcher)));
}
BarDataSet set1;
if (chart1.getData() != null &&
chart1.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) chart1.getData().getDataSetByIndex(0);
set1.setValues(values);
chart1.getData().notifyDataChanged();
chart1.notifyDataSetChanged();
}
else {
set1 = new BarDataSet(values, "taskTypes");
set1.setDrawIcons(false);
dataSets = new ArrayList<>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(2f);
data.setValueTypeface(tfLight);
data.setBarWidth(barWidth);
chart1.setData(data);
// chart1.groupBars(0f, groupSpace, barSpace);
chart1.setFitBars(true);
chart.setData(data);
chart.setFitBars(true);
chart_modality.setData(data);
chart_modality.setFitBars(true);
chart_support.setData(data);
chart_support.setFitBars(true);
}
}
public class CustomXAxisRenderer extends XAxisRenderer {
public CustomXAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis1, Transformer trans) {
super(viewPortHandler, xAxis1, trans);
}
@Override
protected void drawLabel(Canvas c, String formattedLabel, float x, float y,
MPPointF anchor, float angleDegrees) {
String line[] = formattedLabel.split("\n");
Utils.drawXAxisValue(c, line[0], x, y, mAxisLabelPaint, anchor, angleDegrees);
for (int i = 1; i < line.length; i++) { // we've already processed 1st line
Utils.drawXAxisValue(c, line[i], x, y + mAxisLabelPaint.getTextSize() * i,
mAxisLabelPaint, anchor, angleDegrees);
}
}
}
xAxis1.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if (value < 0 || value > taskTypes.size() - 1) {
return "";
}
String valueStr = String.valueOf(taskTypes);
String[] taskList= valueStr.split(",");
return taskList[(int)value];
}
});
xAxis1.setGranularity(1);
xAxis1.setCenterAxisLabels(true);
xAxis1.setTextSize(8f);
xAxis1.setLabelRotationAngle(-30f);
xAxis1.setLabelCount(taskTypes.size());
xAxis1.setGranularityEnabled(true);
build.gradle:
implementation project(':MPChartLib')