MPAndroidChart - Change message “No chart data available”

后端 未结 6 2108
予麋鹿
予麋鹿 2020-12-29 22:22

Is there any way to change the message \"No chart data available\" when the chart is not populated?

Edit: Found the answer



        
相关标签:
6条回答
  • 2020-12-29 22:34

    update answer

    chart.setNoDataText("Description that you want");
    
    0 讨论(0)
  • 2020-12-29 22:36

    You need put pieChart.invalidate() after setNoDataText():

    @Override
        public void setDataMessagePieChart() {
            pieChart.setNoDataText("... your message ...");
            pieChart.invalidate();
        }
    
    0 讨论(0)
  • 2020-12-29 22:41

    If you also want to customize look & feel, you can do it through Paint object:

    mChart.setNoDataText("Description that you want");
    Paint p = mChart.getPaint(Chart.PAINT_INFO);
    p.setTextSize(...);
    p.setColor(...);
    p.setTypeface(...);
    ... 
    
    0 讨论(0)
  • 2020-12-29 22:47

    The Correct answer is here:

     pie_chart.setNoDataText("No Data Available");
     val paint:Paint =  pie_chart.getPaint(Chart.PAINT_INFO)
     paint.textSize = 40f
     pie_chart.invalidate()
    

    You also set other properties like text color, text typeface etc

    0 讨论(0)
  • 2020-12-29 22:50
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_firestore__eintraege__heute);
    
        mChart = findViewById(R.id.chartZuckerHeute);
        mChart.setNoDataText("PUT IT HERE ON TOP; WORKED FOR ME");
    
    0 讨论(0)
  • 2020-12-29 22:50

    It's a little bit old thread, but I had the same issue so my solution was to set nodatatext immediately after the initialization of a chart:

    PieChart pieChart = findViewById(R.id.chart) //in case of fragment view.findViewById(R.id.chart)
    pieChart.setNoDataText("Loading");
    
    0 讨论(0)
提交回复
热议问题