2016-07-11 76 views
1

我在使用MPAndroid庫的Android應用程序中顯示簡單的條形圖。條形圖有時可以完美顯示數據。但是,有時,儘管DataSet具有數據,但它顯示消息「無圖表數據可用」。MPAndroid條形圖僅在點擊圖表區域後顯示圖形,否則顯示「無圖表數據可用」

圖表僅在我點擊圖表區域時顯示。我GOOGLE了這一點,但我找不到解決方案。以下是代碼:

if (mCount > 0){mBarDataSet = new BarDataSet(mBarEntryAssessmentList, "Assessment Count"); 
     mBarDataSet.setBarSpacePercent(5f); 
     mBarData = new BarData(trimmedSubjectNameList, mBarDataSet); 
     mBarData.setValueFormatter(new BarEntryValueFormatter()); // Setting a Value formatter to show Integer data instead of Float 
     mBarChart.setData(mBarData); 
     mBarChart.setDescription(""); 
     mBarChart.setDrawGridBackground(false); 
     mBarChart.setDragEnabled(true); 
     mBarChart.setTouchEnabled(true); 
     mBarChart.setClickable(true); 
     mBarChart.setScaleXEnabled(false); 
     mBarChart.setScaleYEnabled(false); 
     mBarChart.setVisibleXRange(1, 4); 
     mBarChart.setHighlightPerDragEnabled(false); 
     mBarChart.setHighlightPerTapEnabled(true); // set this to true if we want to listen to click events 
     mBarChart.setOnChartValueSelectedListener(StudentProgressActivity.this); 

     XAxis xAxis = mBarChart.getXAxis(); 
     xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); 
     xAxis.setDrawLabels(true); 
     xAxis.setDrawGridLines(false); 
     xAxis.setLabelsToSkip(0); // Shows all the labels as initially we had problems showing all the labels 

     YAxis leftAxis = mBarChart.getAxisLeft(); 
     leftAxis.setDrawLabels(true); 
     leftAxis.setDrawGridLines(false); 
     leftAxis.setAxisMinValue(0f); // Removes padding below YAxis minimum value and XAxis labels 

     YAxis rightAxis = mBarChart.getAxisRight(); 
     rightAxis.setDrawLabels(false); 
     rightAxis.setDrawGridLines(false); 
    } else { 
     mBarChart.setDescription(""); 
     mBarChart.setNoDataText("No Assessments yet"); 
    } 

任何援助將不勝感激。

回答

2

最後,你的條件外,添加:

mBarChart.invalidate(); 
mBarChart.refreshDrawableState(); 

希望,這將解決您的問題。

+1

它確實解決了這個問題。謝謝。 – Bot