|
|
#1 |
|
Generating plots on Iphone
Hi,
I am working on an app, that would that would parse JSON and fetch the values from JSON into an array. Now I would like to plot this array into a plot(scatter). I have until now, parsed the JSON and have the values in an array, now how can i plot the graph? I have heard a lot about COREPLOT, but it too complicated and I want my graph to be as simple as possible. I would really appreciate any help or any example project, that would help me start.
|
|
|
|
0
|
|
|
#2 |
|
I've looked some but haven't found anything I like.
I think I'm just going to roll my own... drawing a simple plot with iOS's drawing commands doesn't seem that difficult. I'm not quite certain, but I think for you, drawing a bunch of points should be as easy as: Code:
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor blueColor] CGColor]));
CGContextFillEllipseInRect(ctx, CGRectMake(x, y, width, height));
// repeat FillEllipseInRect as many times as necessary.
}
Here's the documentation you'll want: CGContext: https://developer.apple.com/library/...reference.html CGGeometry: https://developer.apple.com/library/...reference.html
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! Last edited by ArtOfWarfare; Jan 15, 2013 at 08:27 AM. |
|
|
|
0
|
|
|
#3 |
|
You could also consider using a UIWebView and Google Chart Tools.
__________________
|
|
|
|
0
|
|
|
#4 |
|
Core Plot:
http://code.google.com/p/core-plot/ Google search terms ios plotting and you'll find more info, such as articles on using Core Plot and comparisons with other libraries. |
|
|
|
0
|
|
|
#5 | |
|
The OP said they wanted something easier than coreplot, even though that would be my recommendation too.
Quote:
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
||
|
|
0
|
|
|
#6 | |
|
Quote:
Here's a Ray Wenderlich tutorial that shows a scatter plot: http://www.raywenderlich.com/13271/h...re-plot-part-2 It's part 2, and part 1 has the fundamentals (and a downloadable ready-to-use project). Plotting and charting aren't usually written as isolated components, but as part of a multi-component library of various kinds of plots/charts. So I really don't think there's much possibility of finding a simpler component. If there's a simpler plot/chart library, I don't know what it is. One could write a component from scratch, but that's not exactly a trivial process. And if one already thinks Core Plot is too complex, I don't see how writing it from scratch would be any less so. Perhaps if someone is already skilled at iOS graphics it might be simpler, but that seems unlikely given the question (a skilled poster wouldn't be expected to ask the question at all). So, short answer: Just use Core Plot, and search for tutorials and examples. |
||
|
|
0
|
|
|
#7 |
|
A couple weeks ago I decided to write my own. It took a couple evenings but it was not all that hard. I found it more difficult to try and download and incorporate other pre built ones. I built the background in Photoshop and added it as a subView to the view first.
You then set up a context like so with the size you want returned. Code:
UIGraphicsBeginImageContext(CGSizeMake(300, 200)); CGContextRef context = UIGraphicsGetCurrentContext(); Code:
CGContextSetRGBStrokeColor(); CGContextSetLineWidth(); Code:
CGContextMoveToPoint(); // outside of loop CGContextAddLineToPoint(); // in loop CGContextMoveToPoint(); // in loop Code:
CGContextStrokePath(); Code:
CGContextAddArc(); Code:
UIImage *imageContext = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I was doing a 30 day history so my Photoshop file had 30 lines spaced by 10 pixels, so every loop I multiplied i x 10 to move the graph horizontally. Vertical was easy to find too. I sorted my array so highest number was index 0 and lowest was last index. Then I subtracted the lowest from the highest number and divided that by my total pixel range which was 200 vertically. Code:
float dif = highNum - lowNum;
float range = 200.0 / dif;
Code:
float vSpace = ((highNumber - currentNumber) * myRange);
__________________
I know more than yesterday. Lars |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 06:49 PM.








Linear Mode
