Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing curved lines on the Canvas

 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carlos,

Are there any pages on custom (graphical) components in the book? I'm looking for the best way to draw a curved trend-line between some points in a graph. What would be the best approach to do this? Calculate the intermediary points myself and simply call drawLines(float[] pts, Paint paint) on the Canvas object, or use a Path object with its Cubic and Quadratic Bezier curve methods cubicTo resp. quadTo methods?

Kind regards,

Johan.
 
Carlos Sessa
author
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one hack that teaches you how to draw on a canvas but it's pretty simple.

What you are trying to achieve? You might want to add a dependency as cocos2d-x.
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carlos,

I want to display a chart with one series as bars, and show a trend-line (hence the curved-line requirement). Anything above the trend-line should have a different color. Maybe some axis, legend. That's about it (for a start). Some chart-libs can do bars, or lines. Few can do both in a compound graph. None can do the above / below a trend-line colouring. I'm leaning towards a solution with a custom component.

Kind regards,

Johan.
 
Carlos Sessa
author
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you get a graph library?
I think it's too much work to start using primitives over the canvas to draw graphs
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carlos,

I have not found any which can do what I need (one series in bars, one series in a trend-line, coloring of the exceeding amount in the bars, which is over the trend-line)... Can you recommend a good graph-lib which is highly customisable?

Kind regards,

Johan.
 
Carlos Sessa
author
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used any but google returns:

http://androidplot.com/
https://code.google.com/p/chartdroid/
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carlos, I'll browse around...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic