Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I draw a gradient linechart with mpAndroidChart?

enter image description here

Can I draw a lineChart looks like in the picture? If can, what should I do to change the line colors? Thank you!

what I have draw looks like the picture two,which the line is the same color and there is no yesterday incom.what should I do to change the line into gradient color and only show the last markerView ?

The picture I have drawn.

like image 344
xiance sun Avatar asked Jan 07 '23 04:01

xiance sun


1 Answers

I've found workaround! Please check this tutorial by Lance Gleason. It is pretty simple. Here is some code from it:

@Override
public void onStart() {
    super.onStart();
    getView().post(new Runnable() {
        @Override
        public void run() {
            setupGradient(chartDaySpeed);
        }
    });
}

private void setupGradient(LineChart mChart) {
    Paint paint = mChart.getRenderer().getPaintRender();
    int height = mChart.getHeight();

    LinearGradient linGrad = new LinearGradient(0, 0, 0, height,
            getResources().getColor(android.R.color.holo_green_light),
            getResources().getColor(android.R.color.holo_red_light),
            Shader.TileMode.REPEAT);
    paint.setShader(linGrad);
}

Also here is result:

Line chart gradient result

like image 78
Ivan Loukin Avatar answered Feb 01 '23 09:02

Ivan Loukin