Bhavesh Patadiya
Bhavesh Patadiya

Reputation: 25830

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.

Upvotes: 7

Views: 1546

Answers (2)

Lumis
Lumis

Reputation: 21629

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.

Upvotes: 2

Dan D.
Dan D.

Reputation: 32391

You can add several series of data, each one having a separate color.

Upvotes: 0

Related Questions