add simple line chart in ios application - ios

am new for charts in ios developing apps..
am having two array values like
ProgramenameArray
BudgetCostArray
i want to draw a simple line chat using those arrays use as x-axis and Y-axis respectively...
i tried like this..
- (void)loadChartWithDates
{
NSMutableArray* chartData = [NSMutableArray arr ayWithCapacity:programNmaeIdArray.count];
NSLog(#"the array ^^^^^ values are %# %# ",programNmaeIdArray,programNameArray);
for(int i=0;i<programIdArray.count;i++)
{
chartData[i] = programIdArray[i];
}
NSMutableArray *months = [[NSArray alloc]init];
months=projectNameArray;
// Setting up the line chart
// _chartWithDates.verticalGridStep = 6;
//_chartWithDates.horizontalGridStep = 3;
_chartWithDates.fillColor = nil;
_chartWithDates.displayDataPoint = YES;
_chartWithDates.dataPointColor = [UIColor blackColor];
_chartWithDates.dataPointBackgroundColor = [UIColor fsDarkBlue];
_chartWithDates.dataPointRadius = 2;
_chartWithDates.color = [_chartWithDates.dataPointColor colorWithAlphaComponent:0.3];
_chartWithDates.valueLabelPosition = ValueLabelLeftMirrored;
_chartWithDates.labelForIndex = ^(NSUInteger item)
{
return months[item];
};
_chartWithDates.labelForValue = ^(CGFloat value)
{
return [NSString stringWithFormat:#"%.02f €", value];
};
[_chartWithDates setChartData:chartData];
}
so can anyone help...Thanks in advance.. :)

Related

How can I add in multiple items in model by using array method?

I have an original code as below which is working properly:-
- (ZYSideSlipFilterRegionModel *)commonFilterRegionModelWithKeyword:(NSString *)keyword selectionType:(CommonTableViewCellSelectionType)selectionType {
ZYSideSlipFilterRegionModel *model = [[ZYSideSlipFilterRegionModel alloc] init];
model.containerCellClass = #"SideSlipCommonTableViewCell";
model.regionTitle = keyword;
model.customDict = #{REGION_SELECTION_TYPE:#(selectionType)};
model.itemList = #[[self createItemModelWithTitle:[NSString stringWithFormat:#"Local"] itemId:#"0" selected:NO],
[self createItemModelWithTitle:[NSString stringWithFormat:#"Oversea"] itemId:#"1" selected:NO]];
return model;
}
Now, I plan to change the static value (Oversea / local) to dynamic value. But only 1 item will be displayed.
for (int i = 0; i < filteredArray.count; i++) {
int intItemID = i + 1;
NSString *myNewString = [NSString stringWithFormat:#"%i", intItemID];
model.itemList = #[[self createItemModelWithTitle:[filteredArray[i] valueForKey:#"attribute_name"] itemId:myNewString selected:NO] ];
}
How can I put 2 item in model.itemList? Please help. Thank you.
You can use this way
//step:1 fetch Dictionary like this
for (int i = 0; i < filteredArray.count; i++)
{
NSMutableDictionary *dict = (NSMutableDictionary *)filteredArray[i] ;
int intItemID = i + 1;
NSString *myNewString = [NSString stringWithFormat:#"%i", intItemID];
model.itemList = #[[self createItemModelWithTitle:dict];
}
//Step 2 : You can define your method for Model Like this
- (CommonItemModel *)createItemModelWithTitle:(NSMutableDictionary *)dictModel
{
CommonItemModel *model = [[CommonItemModel alloc] init];
model.itemId = [dictModel valueForKey : #"itemId"];
model.itemName = [dictModel valueForKey:#"itemTitle"];
model.selected = [dictModel valueForKey:[NSNumber numberWithBool:
[[dictModel valueForKey:#"selected"]]]];
return model;
}
//One more thing you are write this in first step
model.itemList = #[[self createItemModelWithTitle:dict];
But the method only return the Model class (CommonItemModel) so if you need any help you shared here
Thanks :)

How to compare two nsarrays with different values?

Hi i have two nsarrays.
Array A:
arrProductSelection = [[NSArray alloc]initWithObjects:#"English",#"German",#"Russian",#"Chinese",#"Spanish",#"French",#"French",#"French",#"French",#"French",#"French",#"French",#"French",nil];
Array B:
arrProductSelectionB = [[NSArray alloc]initWithObjects:#"deselcted",#"selected",#"selected",#"selected",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",nil];
I need to compare two arrays and get the value from array A by comparing with array B having value as selected. That is i should get german,chinese and russian sepearted by comma as nsstring.
Try this:
NSMutableArray *arrSelected = [[NSMutableArray alloc] init];
NSArray *arrProductSelection = [[NSArray alloc]initWithObjects:#"English",#"German",#"Russian",#"Chinese",#"Spanish",#"French",#"French",#"French",#"French",#"French",#"French",#"French",#"French",nil];
NSArray *arrProductSelectionB = [[NSArray alloc]initWithObjects:#"deselcted",#"selected",#"selected",#"selected",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",#"deselcted",nil];
for(int i = 0; i< arrProductSelectionB.count-1;i ++) {
if ([arrProductSelectionB[i] isEqualToString:#"selected"]) {
[arrSelected addObject:arrProductSelection[i]];
}
}
NSString *strSelected = [arrSelected componentsJoinedByString:#","];
NSLog(#"%#", strSelected);//output: German,Russian,Chinese
If you can make this type of array then manage easly.
(
{
flag = deselcted;
name = English;
},
{
flag = selected;
name = German;
},
{
flag = deselcted;
name = Russian;
},
{
flag = deselcted;
name = Chinese;
}
)
==> Array[(dictionary),(dictionary),.....]
if you need result in an array, Here is the function:
NSMutableArray*resultArray=[[NSMutableArray alloc]init];
for(int i=0; i<arrProductSelectionB.count;i++){
if ([[arrProductSelectionB objectAtIndex:i]isEqualToString:#"selected"]) {
[resultArray addObject:[arrProductSelection objectAtIndex:i]];
}
}
resultArrayhave the values which you need.
first i would make sure both arrays have same counters for safety something like
if (arrProductSelection.count == arrProductSelectionB) {
//than all you need is one for cycle something like :
for (int i = 0; i < arrProductionSelectionB.count; i++) {
if ([arrProductionSelectionB[i] isEqualToString: #"selected"]) {
do something magically with arrProductSelection[i];
}
}
}

How to merge 2 NSDictionaries in NSMutableArray having same value in iOS?

I have an NSMutableArray with NSDictionaries like below format
(
{
"login_id" = 95;
consDays = "Mon,Tue";
consEndTime = 12600000;
consStartTime = 9000000;
duration = 10;
id = 58;
isActive = 1;
},
{
"login_id" = 95;
consDays = "Wed,Thur";
consEndTime = 41400000;
consStartTime = 23400000;
duration = 10;
id = 59;
isActive = 1;
},
{
"login_id" = 98;
consDays = "Mon,Tue,Wed,Thur,Fri,Sat,Sun";
consEndTime = 45000000;
consStartTime = 9000000;
duration = 30;
id = 60;
isActive = 1;
},
I can see here first 2 object's with "login_id" 95 are same and i need to merge the contents and make something like this one
{
"login_id" = 95;
consDays = "Mon,Tue-Wed,Thur";
consEndTime = 12600000-41400000;
consStartTime = 9000000-23400000;
duration = 10;
id = 58;
isActive = 1;
},
i have tried with for loop and its not getting clear
for(int i=0;i<[[arr valueForKey:#"data"] count];i++){
NSString *bloginId=[NSString stringWithFormat:#"%#",[[[arr valueForKey:#"data"] valueForKey:#"branchLogin_id"] objectAtIndex:i]];
for(int j=0;j<[[arr valueForKey:#"data"] count];j++){
NSString *firstId=[NSString stringWithFormat:#"%#",[[[arr valueForKey:#"data"] valueForKey:#"branchLogin_id"] objectAtIndex:i]];
NSString *secondId=[NSString stringWithFormat:#"%#",[[[arr valueForKey:#"data"] valueForKey:#"branchLogin_id"] objectAtIndex:j]];
NSLog(#"%#-%#",firstId,secondId);
if([firstId isEqualToString:secondId]){
NSLog(#"%#",[consultationDetailsArray valueForKey:#"branchLogin_id"]);
if([[consultationDetailsArray valueForKey:#"branchLogin_id"] containsObject:secondId]){
NSString *str=[NSString stringWithFormat:#"%#,%#",[[consultationDetailsArray valueForKey:#"consDays"] objectAtIndex:j],[[[arr valueForKey:#"data"] valueForKey:#"consDays"] objectAtIndex:j]];
NSLog(#"consDays %#",str);
}else{
[consultationDetailsArray addObject:[[arr valueForKey:#"data"] objectAtIndex:j]];
}
}
}
}
can anyone help me ?
Ironically I am doing just this same thing right now. Looks like the easiest way is to use a NSMutableDictionary.
// Assume two starting dictionaries.
dictionaryOne;
dictionaryTwo;
//
// Create a mutable copy of the first
NSMutableDictionary *merged = dictionaryOne.mutableCopy;
[merged addEntriesFromDictionary: dictionaryTwo];
//
// merged now contains all keys of both dictionaries
// keys that are in both dictionaries will have values
// from dictionaryTwo.
Hope this helps.

how to get array response from json in string?

I am getting the response from json like this
parcel = (
{
datetime = "2015-08-31 21:48:45";
height = 2;
id = 21;
invoice = NO;
length = 2;
mtype = IN;
"num_item" = 2;
"parcel_number" = 1;
pname = "Parcel number - 1";
"pro_number" = tanu;
status = 1;
type = Exact;
uid = 185;
weight = 2;
width = 2;
wtype = KG;
}
);
I want to get the height,date time,invoice in a string.. How can this be done? AnyOne can help me for this...
NSArray * arr_Parcel = [[NSArray alloc]initWithArray:data];
NSMutableDictionary * temp_Dict = [[NSMutableDictionary alloc]init];
for (int i = 0 ; i < arr_Parcel.count; i++)
{
temp_Dict = [arr_Parcel objectAtIndex:i];
NSString * strHeight = [temp_Dict objectForKey:"height"];
NSString * strdate = [temp_Dict objectForKey:"datetime"];
}
If you are using Swift, use SwiftJSON to work with JSON.
It's easy to use. For example:
var jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let json = JSON(data: jsonData)
print(json["height"].double) // 2
print(json["datatime"].string) // "2015-08-31 21:48:45"
...
Create a NSObject Class and pass the NSDictionary the make a model class.
In your ViewController Class:
" parcel" is your Array
ModelClass * modelClass = [ModelClass alloc] initWithNewsDictionary: parcel[0]];
Create needed variables in ModelClass.h Class.
-(id)initWithNewsDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
self.height = dictionary[#"height"];
self.datetime = dictionary[#"datetime"];
self.invoice = dictionary[#"invoice"];
self.weight = dictionary[#"weight"];
}
return self;
}
Try this :-
NSString *height=[NSString stringWithFormat:#"%#",[[[YourJson valueForKey:#"parcel"] objectAtIndex:0] objectForKey:#"height"]];
NSString *dateTime=[NSString stringWithFormat:#"%#",[[[YourJson valueForKey:#"parcel"] objectAtIndex:0] objectForKey:#"datetime"]];
NSString *invoice=[NSString stringWithFormat:#"%#",[[[YourJson valueForKey:#"parcel"] objectAtIndex:0] objectForKey:#"invoice"]];
NSLog(#"height : %# , date=%# ,invoice=%#",height,dateTime,invoice);

Downloading calendar data in Objective-C

I am trying to download google calendar data.
I am following a tutorial this link according to which implementing some of the GoogleOAuth delegate methods will let me get my desired data.
First I converted the response JSON data into an NSDictionary object and after that, I, NSLog this dictionary, to see the way the returned data is formed which is as shown below.
calendarInfoDict is {
etag = "\"1436255371893000\"";
items = (
{
accessRole = owner;
backgroundColor = "#9a9cff";
colorId = 17;
defaultReminders = (
{
method = popup;
minutes = 30;
}
);
etag = "\"1436255371893000\"";
foregroundColor = "#000000";
id = "sabiranthapa#gmail.com";
kind = "calendar#calendarListEntry";
notificationSettings = {
notifications = (
{
method = email;
type = eventCreation;
},
{
method = email;
type = eventChange;
},
{
method = email;
type = eventCancellation;
},
{
method = email;
type = eventResponse;
}
);
};
primary = 1;
selected = 1;
summary = "sabiranthapa#gmail.com";
timeZone = "Asia/Calcutta";
},
{
accessRole = reader;
backgroundColor = "#92e1c0";
colorId = 13;
defaultReminders = (
);
description = "Displays birthdays of people in Google Contacts and optionally \"Your Circles\" from Google+. Also displays anniversary and other event dates from Google Contacts, if applicable.";
etag = "\"1436255358367000\"";
foregroundColor = "#000000";
id = "#contacts#group.v.calendar.google.com";
kind = "calendar#calendarListEntry";
summary = Birthdays;
timeZone = "Asia/Calcutta";
}
);
kind = "calendar#calendarList";
nextSyncToken = 00001436255371893000;
}
According to tutorial there is a block containing a bunch of information regarding every calendar I have created in Google Calendars inside curly bracket. But I am not getting any events that I have saved which can be seen in Google Calendar after signing in gmail but not in my apps where I need to work with it.
My code is
-(void)responseFromServiceWasReceived:(NSString *)responseJSONAsString andResponseJSONAsData:(NSData *)responseJSONAsData{
NSError *error;
if ([responseJSONAsString rangeOfString:#"calendarList"].location != NSNotFound) {
NSDictionary *calendarInfoDict = [NSJSONSerialization JSONObjectWithData:responseJSONAsData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"calendarInfoDict is %#", calendarInfoDict);
if (error) {
NSLog(#"%#", [error localizedDescription]);
}
else{
NSArray *calendarsInfo = [calendarInfoDict objectForKey:#"items"];
if (_arrGoogleCalendars == nil) {
_arrGoogleCalendars = [[NSMutableArray alloc] init];
}
for (int i=0; i<[calendarsInfo count]; i++) {
NSDictionary *currentCalDict = [calendarsInfo objectAtIndex:i];
NSArray *values = [NSArray arrayWithObjects:[currentCalDict objectForKey:#"id"],
[currentCalDict objectForKey:#"summary"],
nil]; NSArray *keys = [NSArray arrayWithObjects:#"id", #"summary", nil];
[_arrGoogleCalendars addObject:
[[NSMutableDictionary alloc] initWithObjects:values forKeys:keys]];
}
_dictCurrentCalendar = [[NSDictionary alloc] initWithDictionary:[_arrGoogleCalendars objectAtIndex:0]];
[_barItemPost setEnabled:YES];
[_barItemRevokeAccess setEnabled:YES];
[self showOrHideActivityIndicatorView];
But I always end up with condition
if (_arrGoogleCalendars == nil) {
_arrGoogleCalendars = [[NSMutableArray alloc] init];
}
without able to access my events.
How can I download (or access) my Events from google calendar?

Resources