How to draw a line graph having different colors in a single line

I want to make a line graph as follows:

enter image description here

I looked at some Stackoverflow questions , such as How to draw a line using Canvas , How to do Drawing lines with different colors , etc. But I could not figure out how to do it myself.

Question: I have an idea of ​​what I can do with the AChartEngine Line Chart Graph . I'm not sure how much it is possible to create a line graph with AChartEngine ?

What are the alternatives to achieve the same result?

Any help would be greatly appreciated.

+6
source share
2 answers

It is not difficult, you need to create a radial gradient paint with the center in the middle of the curve. Then in colors [] you add as many colors as you want. You can set null for positions , then the colors will be evenly distributed.

 myPaint.setShader(new RadialGradient( float x, float y, float radius, int[] colors, float[] positions, Shader.TileMode tile)); 

You should also apply this only when shaping the path; you will need to get the bounds of the path using

 RectF bounds = new RectF(); myPath.computeBounds(bounds, true); 

Now you can easily find the center and radius.

+2
source

You can add several series of data, each of which has a different color.

0
source

All Articles