2

I wanna achieve such behavior seen below using PieChart of MPAndroidChart library.

PieChart

To do that, I'm setting the ValueFormatter of PieData as the following:

data.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            if(value > 0)
                return floatFormat.format(value) + "\n(XXX)";
            else
                return "";
        }
});

However, the "\n" is somewhat ignored by the ValueFormatter or PieChart, and I'm getting the entire value in a single line. What could be the reason for that? How can I achieve multiline value label behavior as seen in the PieChart example seen above?

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73

1 Answers1

1

As a workaround solution, I set values I wanna show after new line breaks as labels of my PieEntry variables:

PieEntry entry = new PieEntry(value, "(XXX)");

Seems like it does what I wanted to achieve so far. However, it's still not understandable for me that why "\n" does not work while setting ValueFormatter.

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
  • It's because the renderer is only designed to render a single line of text for a value label. You would have to override `drawLabels()` inside a custom renderer – David Rawson Jan 14 '17 at 09:22