Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions iOSPlot/PlotCreator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
F897D6EE13630F560025FE6E /* sample_piechart_data.plist in Resources */ = {isa = PBXBuildFile; fileRef = F897D6ED13630F560025FE6E /* sample_piechart_data.plist */; };
F897D6F113630FD40025FE6E /* PCPieChart.m in Sources */ = {isa = PBXBuildFile; fileRef = F897D6F013630FD40025FE6E /* PCPieChart.m */; };
F897D700136311E60025FE6E /* PieChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F897D6FF136311E60025FE6E /* PieChartViewController.m */; };
F8B8196215D573FB0005945A /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = F8B8196115D573FB0005945A /* JSONKit.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
F8C1B41C136F8056002DDF6C /* sample_linechart_data.json in Resources */ = {isa = PBXBuildFile; fileRef = F8C1B41B136F8056002DDF6C /* sample_linechart_data.json */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -63,8 +62,6 @@
F897D6F013630FD40025FE6E /* PCPieChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PCPieChart.m; path = Shared/PCPieChart.m; sourceTree = "<group>"; };
F897D6FE136311E60025FE6E /* PieChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PieChartViewController.h; path = iPhone/PieChartViewController.h; sourceTree = "<group>"; };
F897D6FF136311E60025FE6E /* PieChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PieChartViewController.m; path = iPhone/PieChartViewController.m; sourceTree = "<group>"; };
F8B8196015D573FB0005945A /* JSONKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSONKit.h; path = JSONKit/JSONKit.h; sourceTree = "<group>"; };
F8B8196115D573FB0005945A /* JSONKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JSONKit.m; path = JSONKit/JSONKit.m; sourceTree = "<group>"; };
F8C1B41B136F8056002DDF6C /* sample_linechart_data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = sample_linechart_data.json; path = "Sample Data/sample_linechart_data.json"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -114,7 +111,6 @@
isa = PBXGroup;
children = (
3794799B13706BB200C0E457 /* iOSPlot */,
F8C1B407136F7FB7002DDF6C /* JSONKit */,
F897D6FE136311E60025FE6E /* PieChartViewController.h */,
F897D6FF136311E60025FE6E /* PieChartViewController.m */,
F83260C01363D91E0045F9DC /* PieChartViewController2.h */,
Expand Down Expand Up @@ -187,15 +183,6 @@
name = "Sample Data";
sourceTree = "<group>";
};
F8C1B407136F7FB7002DDF6C /* JSONKit */ = {
isa = PBXGroup;
children = (
F8B8196015D573FB0005945A /* JSONKit.h */,
F8B8196115D573FB0005945A /* JSONKit.m */,
);
name = JSONKit;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -275,7 +262,6 @@
F88CC4D313684FD30096327F /* LineChartViewController.m in Sources */,
F87DE41A1370D68300347F69 /* PCHalfPieChart.m in Sources */,
F87DE41D1370D82D00347F69 /* HalfPieChartViewController.m in Sources */,
F8B8196215D573FB0005945A /* JSONKit.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
32 changes: 17 additions & 15 deletions iOSPlot/Shared/PCLineChartView.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ - (void)drawRect:(CGRect)rect {
component.colour = PCColorBlue;
}

int x = 0;
int y = 0;
for (int x_axis_index=0; x_axis_index<[component.points count]; x_axis_index++) {
id object = [component.points objectAtIndex:x_axis_index];

Expand All @@ -162,8 +164,8 @@ - (void)drawRect:(CGRect)rect {
CGContextSetStrokeColorWithColor(ctx, [component.colour CGColor]);
CGContextSetLineWidth(ctx, circle_stroke_width);

int x = margin + div_width*x_axis_index;
int y = top_margin + (scale_max-value)/self.interval*div_height;
x = margin + div_width*x_axis_index;
y = top_margin + (scale_max-value)/self.interval*div_height;

CGRect circleRect = CGRectMake(x-circle_diameter/2, y-circle_diameter/2, circle_diameter,circle_diameter);
CGContextStrokeEllipseInRect(ctx, circleRect);
Expand All @@ -182,22 +184,22 @@ - (void)drawRect:(CGRect)rect {
CGContextAddLineToPoint(ctx, x1, y1);
CGContextStrokePath(ctx);
}


if (x_axis_index==[component.points count]-1) {
NSMutableDictionary *info = [NSMutableDictionary dictionary];
if (component.title) {
[info setObject:component.title forKey:@"title"];
}
[info setObject:[NSNumber numberWithFloat:x+circle_diameter/2+15] forKey:@"x"];
[info setObject:[NSNumber numberWithFloat:y-10] forKey:@"y"];
[info setObject:component.colour forKey:@"colour"];
[legends addObject:info];
}


last_x = x;
last_y = y;
}

if (x_axis_index==[component.points count]-1) {
NSMutableDictionary *info = [NSMutableDictionary dictionary];
if (component.title) {
[info setObject:component.title forKey:@"title"];
}
[info setObject:[NSNumber numberWithFloat:x+circle_diameter/2+15] forKey:@"x"];
[info setObject:[NSNumber numberWithFloat:y-10] forKey:@"y"];
[info setObject:component.colour forKey:@"colour"];
[legends addObject:info];
}

}
}

Expand Down
80 changes: 44 additions & 36 deletions iOSPlot/iPhone/LineChartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
*/

#import "LineChartViewController.h"
#import "JSONKit.h"

@implementation LineChartViewController

Expand All @@ -41,6 +40,7 @@ - (id)init
self = [super init];
if (self)
{
NSError *jsonError = nil;
[self.view setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]];
[self setTitle:@"Line Chart"];

Expand All @@ -53,42 +53,50 @@ - (id)init
NSString *sampleFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"sample_linechart_data.json"];
NSString *jsonString = [NSString stringWithContentsOfFile:sampleFile encoding:NSUTF8StringEncoding error:nil];

NSDictionary *sampleInfo = [jsonString objectFromJSONString];
NSDictionary *sampleInfo = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]
options:NSJSONReadingMutableContainers error:&jsonError];

NSMutableArray *components = [NSMutableArray array];
for (int i=0; i<[[sampleInfo objectForKey:@"data"] count]; i++)
{
NSDictionary *point = [[sampleInfo objectForKey:@"data"] objectAtIndex:i];
PCLineChartViewComponent *component = [[PCLineChartViewComponent alloc] init];
[component setTitle:[point objectForKey:@"title"]];
[component setPoints:[point objectForKey:@"data"]];
[component setShouldLabelValues:NO];

if (i==0)
{
[component setColour:PCColorYellow];
}
else if (i==1)
{
[component setColour:PCColorGreen];
}
else if (i==2)
{
[component setColour:PCColorOrange];
}
else if (i==3)
{
[component setColour:PCColorRed];
}
else if (i==4)
{
[component setColour:PCColorBlue];
}

[components addObject:component];
}
[_lineChartView setComponents:components];
[_lineChartView setXLabels:[sampleInfo objectForKey:@"x_labels"]];
if(!jsonError){
NSMutableArray *components = [NSMutableArray array];
for (int i=0; i<[[sampleInfo objectForKey:@"data"] count]; i++)
{
NSDictionary *point = [[sampleInfo objectForKey:@"data"] objectAtIndex:i];
PCLineChartViewComponent *component = [[PCLineChartViewComponent alloc] init];
[component setTitle:[point objectForKey:@"title"]];
[component setPoints:[point objectForKey:@"data"]];
[component setShouldLabelValues:NO];

if (i==0)
{
[component setColour:PCColorYellow];
}
else if (i==1)
{
[component setColour:PCColorGreen];
}
else if (i==2)
{
[component setColour:PCColorOrange];
}
else if (i==3)
{
[component setColour:PCColorRed];
}
else if (i==4)
{
[component setColour:PCColorBlue];
}

[components addObject:component];
}
[_lineChartView setComponents:components];
[_lineChartView setXLabels:[sampleInfo objectForKey:@"x_labels"]];
}else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
message:[jsonError localizedDescription] delegate:self
cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}
}
return self;
}
Expand Down