2016-07-22 86 views
2

如何從BarChat刪除圖例。 我有一些代碼。如何刪除BarChart圖例

float[] yData = { (float)Math.abs(item._Lent),(float) Math.abs(item._Barrow)}; 
    String[] xData = { "salary", "Spends" }; 
    ArrayList<BarEntry> entries = new ArrayList<>(); 
    for (int i = 0; i < yData.length; i++) 
     entries.add(new BarEntry(yData[i], i)); 
    BarDataSet dataset = new BarDataSet(entries, ""); 
    ArrayList<String> labels = new ArrayList<String>(); 
    for (int i = 0; i < xData.length; i++) 
     labels.add(xData[i]); 

    BarData data = new BarData(labels, dataset); 
    mChart.setData(data); // set the data and list of lables into chart 
    BarChart barchart = mChart; 
    Legend legend = barchart.getLegend(); 
    legend.setEnabled(false); 

    YAxis topAxis = barchart.getAxisLeft(); 
    topAxis.setDrawLabels(false); 

    YAxis bottomAxis = barchart.getAxisRight(); 
    bottomAxis.setDrawLabels(false); 

    XAxis rightAxis = barchart.getXAxis(); 
    rightAxis.setDrawLabels(false); 
    bottomAxis.setDrawLabels(false); 

`

此代碼不能正常工作。我讓我跟進。

output

+0

並獲得你想要的輸出? –

回答

1

您需要設置傳說假可見,這樣的:barchart.setLegendVisible(false); - 所以你的代碼會是這個樣子:

//rest of your code 
    .... 
BarData data = new BarData(labels, dataset); 
mChart.setData(data); // set the data and list of lables into chart 
BarChart barchart = mChart; 
barchart.setLegendVisible(false); 
    ... 
//more of your code... 

給它一個嘗試,讓我知道,如果有幫助。你也可以看看這個密切相關的問題here的選定答案。

+0

感謝它現在的工作。 –

2

隱藏與setDescription("")說明:

barchart.setDescription(""); 
+0

謝謝,但我想隱藏傳奇也。 –

+0

你的代碼完美運行,用簡單的活動運行它的最小版本。對我而言,只剩下說明,圖例不可見。我使用MpChart v2.2.3 –