Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Draw line Graph having different colors in Single Line

I want to Make the Line Graph like Below Image :

enter image description here

I've had a look at some Stackoverflow questions such as How to Draw Line with Using Canvas, How To Draw Lines With Different Colors and so on. But I haven't been able to figure it how to do it myself.

Question : I have an idea about what I could make with the AChartEngine Line Chart Graph. I'm not sure, how possible is it to create a line graph with the AChartEngine?

What are the alternatives to achieve the same result?

Any help would be highly appreciated.

like image 240
Bhavesh Patadiya Avatar asked Mar 13 '13 07:03

Bhavesh Patadiya


People also ask

How do I make two lines of different Colours in Excel?

On the Format tab, in the Current Selection group, click Format Selection. tab, expand Fill, and then do one of the following: To vary the colors of data markers in a single-series chart, select the Vary colors by point check box.

How do you make a line a different color?

Change the color of a line Select the line that you want to change. If you want to change multiple lines, select the first line, and then press and hold CTRL while you select the other lines. On the Format tab, click the arrow next to Shape Outline, and then click the color that you want.


1 Answers

That 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. For positions you can set to null, then the colors will be evenly distributed.

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

Also you should apply this only when the path is formed; you will need to get path bounds with

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

Now you can easily find center and radius.

like image 170
Lumis Avatar answered Oct 31 '22 18:10

Lumis