Search code examples
javaandroidpie-chartmpandroidchart

How to change description text size on MPAndroidChart PieChart"?


I have the following settings on MPAndroidChart library by implement a PieChart, but I need to set description text size.

PieData data = new PieData(valsPieX, set1);
    data.setValueTextSize(20f);
    if(usePercentSymbol)
        data.setValueFormatter(new PercentFormatter());

    pieChart.setData(data);
    pieChart.setDrawSliceText(false);
    *pieChart.setDescription(Description);*
    pieChart.highlightValues(null);
    pieChart.invalidate();

Solution

  • pieChart.getDescription().setText("Description Text goes here"); //the text which will be displayed. 
    
    pieChart.getDescription().setTextSize(16f); //sets the size of the label text in density pixels min = 6f, max = 24f, default is 10f, font size will be in dp
    
    pieChart.getDescription().setTextColor(ContextCompat.getColor(context, android.R.color.holo_red_dark)); //the color of the font 
    
    
    pieChart.getDescription().setTextAlign(Paint.Align.RIGHT); //Sets the text alignment of the description text. Default RIGHT 
    

    pieChart: is the your chart object, it can be PieChart, BarChart, LineChart or any other chart type.

    Description: is the object which is returned by getDescription() from chart.