Nata
Nata

Reputation: 309

How to hide value labels when zooming out in MPAndroidChart?

I'm using Swift version of MPAndroidChart and trying to figure out how to hide value labels when a few of them are located too close together and start to overlap on a line chart.

Hiding all the value labels when zoomed out to a certain point works too(still don't know how to do it), but hiding only the ones that are overlapping would be the best.

I know that I can manually call setDrawValues = false, but I want it to be called automatically on zoom.

enter image description here

Upvotes: 0

Views: 672

Answers (1)

Dushyant Yadav
Dushyant Yadav

Reputation: 14

In Android, I use the same as iOS

1: Find the difference between 1st and 2nd index y-axis label(YAxisRenderer)

     for (int i = from; i < to; i++)
     {

        String text = mYAxis.getFormattedLabel(i);

        double value1=Double.parseDouble(mYAxis.getFormattedLabel(1).replace(",",""));

        double value2=Double.parseDouble(mYAxis.getFormattedLabel(2).replace(",",""));


        result=(value2-value1)-40;
        //POPreferences.setDifference(String.valueOf(result));


        c.drawText(text, fixedPosition, positions[i * 2 + 1] + offset, mAxisLabelPaint);
    }

2: Use result variable when text draws on bar or line(BarChartRenderer.java):

  if (result >= vals[k / 2])
    {

    drawValue(c,dataSet.getValueFormatter(),vals[k / 2], entry, i, x, y,color);                                                                                          

      }                                      

Upvotes: 0

Related Questions