Ale*_*dre 10 charts android colors textcolor mpandroidchart
我正在使用MPChartlib作为基本的"条形图"(3个条形和0到100之间的值).
应用程序的背景是黑暗的,所以我想将文本设置为白色,但是当我在chart.xml中设置了存储在string.xml中的颜色代码"FFFFFF"但文本显示为深蓝色时.
//Axe X
XAxis x = barchart.getXAxis();
x.setPosition(XAxisPosition.BOTTOM);
x.setTextColor(R.color.chart_color);
x.setAxisLineColor(R.color.chart_color);
// Design
barchart.setDragEnabled(false);
barchart.setDrawGridBackground(false);
barchart.setTouchEnabled(false);
barchart.setHighlightEnabled(false);
barchart.setMaxVisibleValueCount(101);
barchart.setDescription(null);
barchart.setGridBackgroundColor(R.color.chart_color);
barchart.invalidate(); // refresh
//Axe Y
barchart.getAxisLeft().setAxisMaxValue(100);
barchart.getAxisLeft().setDrawTopYLabelEntry(true);
barchart.getAxisLeft().setDrawAxisLine(false);
barchart.getAxisLeft().setDrawGridLines(false);
barchart.getAxisLeft().setAxisLineColor(R.color.chart_color);
barchart.getAxisLeft().setTextColor(R.color.chart_color);
barchart.getAxisRight().setAxisMaxValue(100);
barchart.getAxisRight().setDrawTopYLabelEntry(true);
barchart.getAxisRight().setAxisLineColor(R.color.chart_color);
barchart.getAxisRight().setTextColor(R.color.chart_color);
Run Code Online (Sandbox Code Playgroud)
我尝试了很多东西和研究,但找不到问题,lib是不是使用相同类型的颜色代码或什么?
谢谢你的帮助,Alex
Phi*_*oda 16
您将资源ID传递给库,而不是实际颜色.
使用它来获得颜色:
int color = ContextCompat.getColor(context, R.color.chart_color);
LineDataSet dataSet = ...;
dataSet.setColor(color);
Run Code Online (Sandbox Code Playgroud)
您也可以在文档中找到它.
如果你想要更改栏颜色更喜欢传递上下文以及下面的例子
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(87f, 0));
entries.add(new BarEntry(90f, 1));
ArrayList<String> labels = new ArrayList<>();
labels.add("title 1");
labels.add("title 2);
BarDataSet dataSet = new BarDataSet(entries, "# of Calls ");
BarData barData = new BarData(labels, dataSet);
dataSet.setColors(new int[]{R.color.color1 , R.color.color2} , context);
barChart.setData(barData);
barChart.animateY(3000 , Easing.EasingOption.EaseOutBack );
Run Code Online (Sandbox Code Playgroud)