0

I have a chart and use mpandroidchart the shape is as shown below enter image description here

how can my line be neat and not too sideways?

Lely Suju
  • 71
  • 2
  • 12

2 Answers2

1

If you are using version above 3 then you need to modify your xAxis as follows and last two lines of code will solve your issue:

 // xAxis customization
    XAxis xAxis = combinedChart.getXAxis();

    // Following code have no effect but you can change it if required
    xAxis.setGranularity(1f);
    xAxis.setGranularityEnabled(true);
    xAxis.setCenterAxisLabels(false);
    xAxis.setDrawGridLines(false);

    //xAxis.setXOffset(2);

    // Setting maximum limit of xAxis
    xAxis.setAxisMaximum(barData().getEntryCount());

    // Setting position of xAxis
    xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED); 

    // This is used to fix bar width of first bar
    **xAxis.setSpaceMin(barData().getBarWidth() / 2f);
    xAxis.setSpaceMax(barData().getBarWidth() / 2f);**
Muhammad Saad Rafique
  • 3,158
  • 1
  • 13
  • 21
0

I'm not sure but its worked for me.

This error comes from X Axis starting point. Set starting point as 1.

xAxis.setAxisMinimum(1); // or xAxis.setAxisMinimum(2);
Gayathri
  • 249
  • 3
  • 13