MPAndroidChart隐藏背景网格

时间:2015-07-07 08:08:33

标签: android linechart mpandroidchart

我在我的Android应用程序中使用MPAndroidChart - LineChart。我想从后台删除网格线。如何从背景中删除网格线?

MPAndroidChart Line Chart Example

图书馆:MPAndroidChart on GitHub

编辑:我使用此库创建了自己的自定义LineChart。我想删除底线。我怎么能这样做? Custom LineChart

7 个答案:

答案 0 :(得分:90)

使用此:

mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);

请注意您可能需要右轴或两者。这取决于您实际使用的轴。

<强>更新 是轴线吗?如果是,则只需chart.getXAxis().setEnabled(false)

也可以:chart.getAxisLeft().setDrawAxisLine(false)

答案 1 :(得分:8)

简单地在三行以下删除条形图中的水平和垂直线。 enter image description here

barChart.getAxisRight().setDrawGridLines(false);
barChart.getAxisLeft().setDrawGridLines(false);
barChart.getXAxis().setDrawGridLines(false);

enter image description here

答案 2 :(得分:5)

以上所述都不帮助我隐藏所有轴线。我只需要干净的床单。 下面的代码完成了工作:

    barChart.xAxis.isEnabled = false
    barChart.axisLeft.isEnabled = false
    barChart.axisRight.isEnabled = false

在kotlin中提供,在Java方法中将如下所示:setEnabled(false)

答案 3 :(得分:4)

使用此代码清除带有标签的所有行:

mChart.setTouchEnabled(true);
mChart.setClickable(false);
mChart.setDoubleTapToZoomEnabled(false);
mChart.setDoubleTapToZoomEnabled(false);

mChart.setDrawBorders(false);
mChart.setDrawGridBackground(false);

mChart.getDescription().setEnabled(false);
mChart.getLegend().setEnabled(false);

mChart.getAxisLeft().setDrawGridLines(false);
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisLeft().setDrawAxisLine(false);

mChart.getXAxis().setDrawGridLines(false);
mChart.getXAxis().setDrawLabels(false);
mChart.getXAxis().setDrawAxisLine(false);

mChart.getAxisRight().setDrawGridLines(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getAxisRight().setDrawAxisLine(false);

并使用它删除所有点的值:

LineDataSet set1;
set1.setDrawValues(false);

答案 4 :(得分:2)

隐藏背景网格

    chart.getXAxis().setDrawGridLines(false);
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getAxisRight().setDrawGridLines(false);

答案 5 :(得分:0)

要从图表中删除边框,可以使用setDrawBorder(boolean)属性。

chart.setDrawBorders(false);

答案 6 :(得分:0)

去除外线的代码:

 let item = self.type[indexPath.row]
     // item type is the property that holds parameter String values: you can imagine that it is the cell indices
    // subCategory & category is the parameter String values where I assign them upon the cell selection and pass it to the API calling func as a value
        switch item.type {
        case .Male:
            self.type[getIndex(type: .Male)].category = "Male"
            self.type[getIndex(type: .Male)].subCategory = "Male"
            
            self.category = self.type[getIndex(type: .Male)].category
            self.subCategory = self.type[getIndex(type:.Male)].subCategory
           //The Api Call func
            getData(categoryKey: self.category!, subCategoryKey: self.subCategory!)
            print(category!,subCategory!)
         case .Female:
            self.type[getIndex(type: .Female)].category = "Female"
            self.type[getIndex(type: .Female)].subCategory = "Female"
            
            self.category = self.type[getIndex(type: .Female)].category
            self.subCategory = self.type[getIndex(type:.Female)].subCategory
           
            getData(categoryKey: self.category!, subCategoryKey: self.subCategory!)
            print(category!,subCategory!)
}

去除网格线的代码

barChart.getAxisRight().setDrawAxisLine(false); 

barChart.getAxisLeft().setDrawAxisLine(false); 

barChart.getXAxis().setDrawAxisLine(false);