gpt4 book ai didi

android - 如何设置饼图的标签颜色?

转载 作者:行者123 更新时间:2023-11-29 16:38:11 24 4
gpt4 key购买 nike

我正在使用 mpandroidchart用于创建饼图的库。

我想在饼图上设置文本标签的格式,但我不知道该怎么做。我尝试使用

data.setValueTextColor(ContextCompat.getColor(getActivity(),R.color.black));

但是,它只会改变数据的值,不会改变标签。另外,我想成为饼图中的标签我也尝试使用以下代码,

PieEntry entry2=new PieEntry(50-scratches,"Remaining \nScratches");

但是,它没有用。

我的代码如下:

private void setPiechart(float scratches) {

List<PieEntry> values = new ArrayList<>();

PieEntry entry1=new PieEntry(scratches,"Scratches");
PieEntry entry2=new PieEntry(50-scratches,"Remaining \nScratches");

values.add(entry1);
values.add(entry2);

PieDataSet dataSet = new PieDataSet(values,"");

dataSet.setColors(ContextCompat.getColor(getActivity(),R.color.color_veridoc_gradient1),
ContextCompat.getColor(getActivity(),R.color.colorBgChat));

dataSet.setHighlightEnabled(true);
dataSet.setAutomaticallyDisableSliceSpacing(true);

dataSet.setSliceSpace(10);

PieData data=new PieData(dataSet);
data.setValueTextSize(20f);
data.setValueTextColor(ContextCompat.getColor(getActivity(),R.color.black));


pieChart.setData(data);
Description description=new Description();
description.setText("Scratches ");
pieChart.setDescription(description);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleRadius(10f);

pieChart.animateY(500);

Legend legend = pieChart.getLegend();
legend.setEnabled(true);

legend.setTextColor(Color.BLACK);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pieChart.setElevation(10);
}

}

我得到的结果是: enter image description here

我想做的事情简而言之

  1. change the label color inside the pie chart (from white to black)
  2. Prevent the label from going outside the pie chart. (e.g. Remaining Scratches as shown in image)

有人可以帮我吗?

我还尝试了以下链接中提到的这些解决方案。

link 1 link 2

但它们似乎都不起作用。

最佳答案

使用

   pieChart.setEntryLabelColor(Color.BLACK);

关于android - 如何设置饼图的标签颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51998916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com