permaculture playing cards*
The moose likes Android and the fly likes Drawing curved lines on the Canvas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Drawing curved lines on the Canvas" Watch "Drawing curved lines on the Canvas" New topic
Author

Drawing curved lines on the Canvas

Johan Pelgrim
Ranch Hand

Joined: Jul 07, 2003
Posts: 105

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.


Johan Pelgrim, The Netherlands
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
Carlos Sessa
author
Greenhorn

Joined: Apr 17, 2013
Posts: 14
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

Joined: Jul 07, 2003
Posts: 105

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

Joined: Apr 17, 2013
Posts: 14
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

Joined: Jul 07, 2003
Posts: 105

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

Joined: Apr 17, 2013
Posts: 14
I haven't used any but google returns:

http://androidplot.com/
https://code.google.com/p/chartdroid/
Johan Pelgrim
Ranch Hand

Joined: Jul 07, 2003
Posts: 105

Thanks Carlos, I'll browse around...
 
wood burning stoves
 
subject: Drawing curved lines on the Canvas
 
Similar Threads
How to create an image from JPanel contents?
How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)?
Need help to understand about Canvas
Which component to use to respond to mouse input
applets