PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.54k stars 9.01k forks source link

LineChart: how to display gradient below line #104

Closed ludriv closed 9 years ago

ludriv commented 10 years ago

Hello Phil, I want to draw gradient below line: line color with 1 or configurable alpha to line color 0 alpha. How can I do this?

PhilJay commented 10 years ago

Can you be more specific, I'm not really sure what you mean.

Have you noticed the method setDrawFilled(boolean enabled) in the LineDataSet class?

Regards, Phil

ludriv commented 10 years ago

Thanks for answering. Yes, setDrawFilled(boolean enabled) works but it's a plain color, I would like a gradient and, if possible, choose components colors and orientation. Here an example example

romangromov commented 9 years ago

Hi @ludriv,

looks awesome! It would be great to have this feature!

sy-tang commented 9 years ago

@ludriv you can add a gradient shader to the mRenderPaint to do that. It works for me.

PhilJay commented 9 years ago

Looks very interesting, I'm thinking about adding this feature. In the meantime, you cand do a workaround like this (similar to what sy-tang mentioned):

Inside the library:

mRenderPaint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));

// data preparation...

// data drawing
mDrawCanvas.drawPath(..., mRenderPaint);

mRenderPaint.setShader(null);
ludriv commented 9 years ago

Thanks it works!

classified commented 9 years ago

I tried to do as you said Phil But it's doesn't work for me. Can you please tell me where to edit in LIbrary and how to Use it.? Thanks.

woutergoossens commented 9 years ago

I want to do the same. Use a gradient below my line. How would this be possible

jcgsxr commented 8 years ago

This I did this by modifying the drawFilledPath method in the LineChartRenderer class like so:

Paint paint = new Paint();
paint.setShader(new LinearGradient(0, 0, 0, c.getHeight(), 0x80FFFFFF, 0x00FFFFFF, Shader.TileMode.CLAMP));

c.save();
c.clipPath(filledPath);

//int color = (fillAlpha << 24) | (fillColor & 0xffffff);
//c.drawColor(color);
c.drawPaint(paint);
c.restore();
danielvivek2006 commented 7 years ago

I did it simply by adding setDrawableFilled which takes drawable as parameter. In that drawable, i've added gradient shape and It worked for me

arpitgarg commented 6 years ago

@delhmela Did you got any way to do that.

enes-sakut commented 6 years ago

@arpitgarg yeap I used MPAndroidChart and changed MPAndroidChart's codes )

NAT313 commented 6 years ago

@PhilJay animations are laggy in api 19 but without animations the app with the chart is quiet fast by the way thanks man great library.