Akash Patil
Akash Patil

Reputation: 476

Gradient Color to MPAndroid Barchart

I want to use my custom gradient for MPAndroid Bar chart. I have made my custom drawable color as below:

<item android:id="@android:id/progress">
    <clip
        android:clipOrientation="vertical"
        android:gravity="bottom">
        <shape>
            <gradient
                android:startColor="#00AEEE"
                android:centerColor="#0086CA"
                android:endColor="#315AA6"
                android:angle="90" />
        </shape>
    </clip>
</item>

I tried assigning it to my barchart as follows: barDataSet.setColor(R.drawable.gradient_color); Another issue is that I want to display Right Side YAxis label from 0-10.9 . but it is dynamically changing to points close to minimum, i mean to say, if my minimum result is 6 den it skips numbers below 6

enter image description here

But it is not what i want. I want my result to be like below: enter image description here

Upvotes: 2

Views: 4007

Answers (3)

iamsr
iamsr

Reputation: 411

New version supports gradient -

val barDataSet = BarDataSet(entries, "Days")
val startColor =
        ContextCompat.getColor(requireContext(), R.color.colorPrimary)
    val endColor = ContextCompat.getColor(requireContext(),  
                   R.color.colorPrimaryDark)
barDataSet.setGradientColor(startColor, endColor)

if you want to use more gradients just make a list of GradientColor and pass it to barDataSet.setGradientColors() function

Upvotes: 1

Elric
Elric

Reputation: 84

Try following code it might be close enough:

 Paint mPaint = barChart.getRenderer().getPaintRender(); mPaint.setShader(new   
  SweepGradient(350,120,Color.parseColor("#FFF212"),Color.parseColor("#FCE121")));

Upvotes: 2

Goku
Goku

Reputation: 53

Try the following, you will get a better result.

paint.setShader(new LinearGradient(0,0,0,10,new   int[]{Color.parseColor("#00AEEE"),Color.parseColor("#0086CA"),Color.parseColor("#315AA6")},new float[]{0,2,2}, Shader.TileMode.CLAMP));

Upvotes: 2

Related Questions