Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineChart: how to display gradient below line #104

Closed
ludriv opened this issue Sep 22, 2014 · 13 comments
Closed

LineChart: how to display gradient below line #104

ludriv opened this issue Sep 22, 2014 · 13 comments
Labels
enhancement improves upon existing functionality

Comments

@ludriv
Copy link

ludriv commented Sep 22, 2014

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
Copy link
Owner

PhilJay commented Sep 22, 2014

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
Copy link
Author

ludriv commented Sep 22, 2014

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
Copy link
Contributor

Hi @ludriv,

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

@sy-tang
Copy link

sy-tang commented Sep 23, 2014

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

@PhilJay
Copy link
Owner

PhilJay commented Sep 24, 2014

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
Copy link
Author

ludriv commented Sep 25, 2014

Thanks it works!

@PhilJay PhilJay added the enhancement improves upon existing functionality label Sep 25, 2014
@classified
Copy link

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.

@PhilJay PhilJay closed this as completed Feb 25, 2015
@woutergoossens
Copy link

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

@jcgsxr
Copy link

jcgsxr commented Nov 26, 2015

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
Copy link

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
Copy link

@delhmela Did you got any way to do that.

@enes-sakut
Copy link

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

@NAT313
Copy link

NAT313 commented Mar 14, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improves upon existing functionality
Projects
None yet
Development

No branches or pull requests