Draw graphs (X,Y..)

Hi there,
Very excited to be part of this community.
I’m beginner in Corona and I’m desperately looking for help on how to draw graphs: the X and Y should be scaled to the screen as per the min/max values.
Possibility to draw multiples per graph (exp: player 1 (blue), and player 2 (red)).
Nice to have: Possibility to export the graph as an image.

I will be grateful for your help.

Thanks
Dev

[import]uid: 94804 topic_id: 15850 reply_id: 315850[/import]

Hi there Dev. I don’t know about any official graph APIs or tools but you could make this effect with use of the line API (using display.newLine). Use this to draw x and y values for a line and then you can append x and y coordinates for further lines extending from a single line. The lines can be coloured blue or red using object:setColor(r,g,b) .

Finally, you want to save the graph as an image. This code can help you based from the ScreenCaptureToFile Sample Code included in Corona SDK (Lines 50-52 of main.lua)

[lua] – Capture the screen and save it to file.
local baseDir = system.DocumentsDirectory
display.save( display.currentStage, “entireScreen.jpg”, baseDir )[/lua]

For more reading on the display.newLine API check it out here: http://developer.anscamobile.com/content/displaynewline

If you need ideas on how to set the x and y values on the lines, try getting your screen size you are developing for and dividing it by the maximum value you need. Eg. 480 (screen size) / 5000 (maximum score) for the y-axis. This ratio can then be multiplied against your score (480/5000 * 2360) = 226.56. Rounding this result can give you the coordinate you need.

I hope I helped and good luck with your Corona journey,

Luke. [import]uid: 75643 topic_id: 15850 reply_id: 58577[/import]

Thanks Luke for the feedback. [import]uid: 94804 topic_id: 15850 reply_id: 58579[/import]

Dev,

you can have a look at this custom Bar Graph here for purchase

or you can also have a look at the Corona UIAdvance+Graph Library (From 3rd Party)

and if you want, you can also have a look at the video post above and try to make it yourself in code…

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15850 reply_id: 58580[/import]