2015-04-22 22 views
7

Tôi đang sử dụng MPChartlib cho "Barchart" cơ bản (3 thanh và giá trị từ 0 đến 100).Cách đặt màu trong MPAndroidChart?

nền của ứng dụng tối nên tôi muốn đặt văn bản màu trắng nhưng khi tôi đặt văn bản có mã màu "FFFFFF" trong biểu đồ_color được lưu trữ trong string.xml nhưng văn bản xuất hiện bằng màu xanh đậm.

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

Tôi đã thử rất nhiều thứ và nghiên cứu nhưng không thể tìm thấy vấn đề, lib không sử dụng cùng một loại mã màu hay gì đó?

Nhờ sự giúp đỡ của bạn, Alex

Trả lời

12

Bạn đang qua id tài nguyên vào thư viện, không phải là màu sắc thực tế.

Sử dụng này để có được màu sắc:

int color = getResources().getColor(R.color.chart_color); 
    something.setColor(color); 

Bạn cũng có thể tìm thấy điều này trong documentation.

+0

@Philipp Jahoda thiết lập màu sắc thanh dựa trên giá trị trục y, là nó có thể sử dụng MPAndroidChart? –

6

nếu bạn muốn thay đổi các thanh màu thích bối cảnh đường chuyền cũng như ví dụ dưới đây

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); 
Các vấn đề liên quan