如何在 MPAndroidChart 中隐藏图例和轴?
How to hide legends and axis in MPAndroidChart?
他们是否有可能从这张图片中隐藏所有圆形项目。
我用过下面的代码,
public void setDataList(List<HorizontalBarChartData> dataList, Resources resources) {
ArrayList<String> categories = new ArrayList<String>();
ArrayList<BarEntry> values = new ArrayList<BarEntry>();
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
BarDataSet set1;
for (int i = 0; i < dataList.size(); i++) {
categories.add(dataList.get(i).getName());
values.add(new BarEntry(dataList.get(i).getValue(), i));
}
/*set1 = new BarDataSet(values, "Income, Expense, Disposable Income");*/
set1 = new BarDataSet(values, "Category 1, Category 2, Category 3");
set1.setBarSpacePercent(35f);
set1.setColors(new int[]{resources.getColor(R.color.cyan_blue), resources.getColor(R.color.vermilion_tint), resources.getColor(R.color.sea_green)});
dataSets.add(set1);
BarData data = new BarData(categories, dataSets);
data.setValueTextSize(10f);
horizontalBarChart.setData(data);
}
更新
如何隐藏这张图片的圆角部分?
以下代码适用于饼图。尝试为您的图表获取相同的方法。
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.NONE);
是的,可以,只需使用以下代码:
mChart.setDescription(""); // Hide the description
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getXAxis().setDrawLabels(false);
mChart.getLegend().setEnabled(false); // Hide the legend
以下代码适用于所有图表
Legend l = mchart.getLegend();
l.setEnabled(false);
.
根据
mChart.getXAxis().setDrawLabels(false);
将隐藏整个 X-Axis(根据此问题的要求)。
为了定位 X-Axis,以下代码有效。
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
位置可以设置为
- 底部
- BOTH_SIDED
- BOTTOM_INSIDE
- 顶部
- TOP_INSIDE
如果您试图仅隐藏特定的侧轴而不是隐藏整个轴,这会有所帮助。
chart=(LineChart) findViewById(R.id.Chart);
chart.getLegend().setEnabled(false); // for hiding square on below graph
似乎mChart.setDescription()
不再接受字符串。
该方法现在接受描述 Class 的实例,如下所示:
mChart.setDescription(Description description)
因此,要修改或删除图表描述,您可以按如下方式进行
Description description = new Description();
description.setText("");
mChart.setDescription(description);
要隐藏说明,请使用此
mChart.getDescription().setEnabled(false)
MPAndroidChart:v3.1.0
的 Kotlin 解决方案
chart.description.isEnabled = false // hide the description
chart.legend.isEnabled = false // hide the legend
chart.xAxis.setDrawLabels(false) // hide bottom label
chart.axisLeft.setDrawLabels(false) // hide left label
chart.axisRight.setDrawLabels(false) // hide right label
我遇到了问题,当我使用 mChart.getLegend().setEnabled(false)
时,底部的 xAxis 标签被切断了
现在我改用 chart.getLegend().setForm(Legend.LegendForm.NONE);
并且标签不再被切割
他们是否有可能从这张图片中隐藏所有圆形项目。
我用过下面的代码,
public void setDataList(List<HorizontalBarChartData> dataList, Resources resources) {
ArrayList<String> categories = new ArrayList<String>();
ArrayList<BarEntry> values = new ArrayList<BarEntry>();
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
BarDataSet set1;
for (int i = 0; i < dataList.size(); i++) {
categories.add(dataList.get(i).getName());
values.add(new BarEntry(dataList.get(i).getValue(), i));
}
/*set1 = new BarDataSet(values, "Income, Expense, Disposable Income");*/
set1 = new BarDataSet(values, "Category 1, Category 2, Category 3");
set1.setBarSpacePercent(35f);
set1.setColors(new int[]{resources.getColor(R.color.cyan_blue), resources.getColor(R.color.vermilion_tint), resources.getColor(R.color.sea_green)});
dataSets.add(set1);
BarData data = new BarData(categories, dataSets);
data.setValueTextSize(10f);
horizontalBarChart.setData(data);
}
更新
如何隐藏这张图片的圆角部分?
以下代码适用于饼图。尝试为您的图表获取相同的方法。
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.NONE);
是的,可以,只需使用以下代码:
mChart.setDescription(""); // Hide the description
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getXAxis().setDrawLabels(false);
mChart.getLegend().setEnabled(false); // Hide the legend
以下代码适用于所有图表
Legend l = mchart.getLegend();
l.setEnabled(false);
.
根据
mChart.getXAxis().setDrawLabels(false);
将隐藏整个 X-Axis(根据此问题的要求)。
为了定位 X-Axis,以下代码有效。
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
位置可以设置为
- 底部
- BOTH_SIDED
- BOTTOM_INSIDE
- 顶部
- TOP_INSIDE
如果您试图仅隐藏特定的侧轴而不是隐藏整个轴,这会有所帮助。
chart=(LineChart) findViewById(R.id.Chart);
chart.getLegend().setEnabled(false); // for hiding square on below graph
似乎mChart.setDescription()
不再接受字符串。
该方法现在接受描述 Class 的实例,如下所示:
mChart.setDescription(Description description)
因此,要修改或删除图表描述,您可以按如下方式进行
Description description = new Description();
description.setText("");
mChart.setDescription(description);
要隐藏说明,请使用此
mChart.getDescription().setEnabled(false)
MPAndroidChart:v3.1.0
chart.description.isEnabled = false // hide the description
chart.legend.isEnabled = false // hide the legend
chart.xAxis.setDrawLabels(false) // hide bottom label
chart.axisLeft.setDrawLabels(false) // hide left label
chart.axisRight.setDrawLabels(false) // hide right label
我遇到了问题,当我使用 mChart.getLegend().setEnabled(false)
现在我改用 chart.getLegend().setForm(Legend.LegendForm.NONE);
并且标签不再被切割