Group Group Group Group Group Group Group Group Group

Creating Graphs in watchOS

#1

I’m looking for information (or capabilities) of creating different types of graphs on the watchOS. I’ve downloaded the latest watchos tutorial and chapter 9 has some code for basically a line, but i cant seem to find anything about other types of graphs - specifically a bar chart. I understand that you cant plot a true graph and it will be just a picture of it, but even the creation of it seems to be escaping me at this point. and this is something that i’m hoping to do exclusively on the watch, not passing back and forth from the phone.

#2

I’m pretty sure the watch can use simple Core Graphics calls and you could use the CG range of calls to create lines just as you would in draw(rect:) on iOS. I would begin experimenting by confining myself to calls available on the watch like strokePath.

Maybe get started by drawing a simple bar chart using a series of line primitives. Set the width of your lines and each of those becomes a bar. Iterate over all the data points you want to display, choosing the line width and line spacing appropriately so it will fill all the space. Scale the length of each of those lines so that the largest value represents the longest line and others are proportional. Finally draw some axes the same way.

You will need to get a core graphics context, then repeatedly create a path describing each line, then draw it after setting color and width.

#3

Interesting route. Thank you, I’ll give it a shot.