如何在MPAndroidChart中设置颜色? [英] How to set colors in MPAndroidChart?

查看:569
本文介绍了如何在MPAndroidChart中设置颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将MPChartlib用于基本的"Barchart"(3个小节,值在0到100之间).

I'm using MPChartlib for a basic "Barchart" (3 bars and values between 0 and 100).

应用程序的背景是深色的,因此我想将文本设置为白色,但是当我在string.xml中存储的chart_color中将颜色代码设置为"FFFFFF"的文本时,却显示为深蓝色.

the background of the app is dark so I'd like to put the text in white but when I set the text with color code "FFFFFF" in chart_color stored in string.xml but the text appear in dark blue.

   //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);

我尝试了很多事情和研究,但是找不到问题,lib是否没有使用相同类型的颜色代码或其他东西?

I tried lots of things and research but couldn't find the issue, does the lib doesn't use the same kind of color code or something ?

感谢您的帮助, 亚历克斯

Thanks for your help, Alex

推荐答案

您正在将资源ID而不是实际颜色传递给库.

使用它来获取颜色:

    int color = ContextCompat.getColor(context, R.color.chart_color);

    LineDataSet dataSet = ...;
    dataSet.setColor(color);

您还可以在文档中找到

这篇关于如何在MPAndroidChart中设置颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆