Combined Charts in iOS-Chart - Negative values for Line Chart are not rendered - ios-charts

I am using io-Charts (https://github.com/danielgindi/Charts/).
I will have to show a bar chart and a line chart in the combined chart.
The xAxis will reflect values from -12 to 12 and y value ranges between -3000 to 3000.While the bar diagram is rendered properly for negative y and x axis , the line chart is not showing for values less than 0.As suggested in the following link ,
Negative values not displayed in line charts using ios-charts using Swift
I have set the _chartView.xAxis.axisMinimum = -12; // to start from -12 and not 0.
Please find below the current graph ,
The Setting for the chart view and data set for the line chart ,
- (LineChartData *)generateLineData
{
LineChartData *d = [[LineChartData alloc] init];
NSMutableArray *entries = [[NSMutableArray alloc] init];
[entries addObject:[[ChartDataEntry alloc] initWithX:0 y:-3000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:0.5 y:-999]];
[entries addObject:[[ChartDataEntry alloc] initWithX:1 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:2 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:3.5 y:-1300]];
[entries addObject:[[ChartDataEntry alloc] initWithX:4 y:-900]];
[entries addObject:[[ChartDataEntry alloc] initWithX:5 y:-1200]];
[entries addObject:[[ChartDataEntry alloc] initWithX:6 y:-2500]];
[entries addObject:[[ChartDataEntry alloc] initWithX:8 y:-1300]];
[entries addObject:[[ChartDataEntry alloc] initWithX:9 y:1400]];
[entries addObject:[[ChartDataEntry alloc] initWithX:11 y:-900]];
[entries addObject:[[ChartDataEntry alloc] initWithX:12 y:-3000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-1 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-2 y:-1300]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-4 y:-1100]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-5 y:-1500]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-6 y:-1500]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-8 y:-1100]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-9 y:-1000]];
[entries addObject:[[ChartDataEntry alloc] initWithX:-11 y:-1500]];
LineChartDataSet *set = [[LineChartDataSet alloc] initWithValues:entries label:#"Line DataSet"];
[set setColor:[UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f]];
set.lineWidth = 2.5;
set.fillColor = [UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f];
set.mode = LineChartModeHorizontalBezier;
set.drawValuesEnabled = NO;
set.drawCirclesEnabled = NO;
set.axisDependency = AxisDependencyLeft;
[d addDataSet:set];
return d;
}
I am not sure if I am missing some setting for the chartview.

Fixed this by reordering the line chart data set with x values from -12 to 12 , in my original question , the data set was mixed and not in a proper order for the line chart.

Related

create navigationbar dynamatically in ios

This is the static navigation bar how i set in my project , but want to do in dynamic way, here is the two type of code...
viewsArray = [[NSArray alloc] init];
AfterloginViewController *toolsnavigation = [[AfterloginViewController alloc] init];
toolsnavigation.tabBarItem.image = [UIImage imageNamed:#"cool.png"];
[toolsnavigation setTitle:#"Tools"];
UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:toolsnavigation];
MapViewController *myridenavigation = [[MapViewController alloc] init];
myridenavigation.tabBarItem.image = [UIImage imageNamed:#"cool.png"];
[myridenavigation setTitle:#"Login"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myridenavigation];
viewsArray = [NSArray arrayWithObjects:nav0,nav1,nav2,nav3,nav4,nav5,nav6,nav7,nav8, nil];
tabbarController = [[UITabBarController alloc] init];
[tabbarController setViewControllers:viewsArray];
self.window.rootViewController = tabbarController;
Now i am getting data from the URL and want to assign it as dynamically navigation item. But i m puzzeled now, any idea how to do it.
NSString *loginstring = [NSString stringWithFormat:#"%#nvgationarray.php",mydomainurl];
NSMutableData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: loginstring]];
NSDictionary *allData = [NSJSONSerialization JSONObjectWithData:dataURL options:0 error:nil];
int i = 0;
for(NSDictionary *stat in allData)
{
NSString *ssprst = [stat objectForKey:#"tab_type"];
NSString *ssprst1 = [stat objectForKey:#"tab_name"];
NSString *ssprst2 = [stat objectForKey:#"tab_id"];
NSString *ssprst3 = [stat objectForKey:#"icon"];
NSLog(#"all data ===== :::: %# %# %# %#",ssprst,ssprst1,ssprst2,ssprst3);
NSLog(#"++++++++++++++++++++++++++++++++++++++++++++++");
AbcViewController *myridenavigation = [[AbcViewController alloc] init];
myridenavigation.tabBarItem.image = [UIImage imageNamed:#"cool.png"];
[myridenavigation setTitle:#"Login"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myridenavigation];
i++;
}
if you want to retain memory UINavigationController . I suggest you hold it in NSMutableArray.
In header file
#property(nonatomic, strong) NSMutableArray* arrayNavigationCont;
In implementation file
#synthesize arrayNavigationCont = _arrayNavigationCont;
do not forget also to init array in somewhere relevant like viewDidLoad
self.arrayNavigationCont = [[NSMutableArray alloc] init];
In your method
...
for(NSDictionary *stat in allData)
{
...
AbcViewController *myridenavigation = [[AbcViewController alloc] init];
myridenavigation.tabBarItem.image = [UIImage imageNamed:#"cool.png"];
[myridenavigation setTitle:#"Login"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myridenavigation];
[self.arrayNavigationCont addObject:nav1]
i++;
}
Later you can access you navigationConts somewhere again
for(int i = 0; i < [self.arrayNavigationCont count]; i++)
{
UINavigationController *nav1 = [self.arrayNavigationCont objectAtIndex:i];
//do sth with nav1 to your like
}

Is there a way to shorten my CountryViewController.m without hard coding?

I would like to know if there's a way to shorten my CountryViewController.m because I will be adding another else if statement every time I add a new country.
I am using a UITableViews that pushes a new table view.
RootViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    ASIA = [[NSMutableArray alloc] init];
    EU = [[NSMutableArray alloc] init];
    [ASIA addObject: #"China"];
    [ASIA addObject: #"Japan"];
    [ASIA addObject: #"Korea"];
    [EU addObject: #"France"];
    [EU addObject: #"Italy"];
    [EU addObject: #"Switzerland"];
    self.title = #"Continent";
}
CountryViewController.m
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated];
if ([self.title isEqualToString: #"China"]) {
_listOfCities = [[NSMutableArray alloc] init];
[_listOfCities addObject: #"Beijing"];
[_listOfCities addObject: #"Hong Kong"];
}
else if ([self.title isEqualToString: #"Japan"]){
_listOfCities = [[NSMutableArray alloc] init];
[_listOfCities addObject: #"Tokyo"];
}
else if ([self.title isEqualToString: #"Korea"]){
_listOfCities = [[NSMutableArray alloc] init];
[_listOfCities addObject: #"Seoul"];
}
else if ([self.title isEqualToString: #"France"]){
_listOfCities = [[NSMutableArray alloc] init];
[_listOfCities addObject: #"Paris"];
[_listOfCities addObject: #"Versailles"];
}
else if ([self.title isEqualToString: #"Italy"]){
_listOfCities = [[NSMutableArray alloc] init];
[_listOfCities addObject: #"Rome"];
}
else if ([self.title isEqualToString: #"Switzerland"]){
_listOfCities = [[NSMutableArray alloc] init];
[_listOfCities addObject: #"Bern"];
}
[self.tableView reloadData];
}
A simple way is to use a property list and include that as a bundle resource (i.e. just add it to your project).
For example, if your property list looks like this:
You can then load it with
countries = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"CountryData" ofType:#"plist"]];
and use it as a normal dictionary or array, i.e.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated];
NSString* countryName = self.title;
NSDictionary* country = [countries objectForKey:countryName];
NSArray* cities = [country objectForKey:#"Cities"];
NSString* continent = [country objectForKey:#"Continent"];
_listOfCities = cities;
[self.tableView reloadData];
}
Plist files can be edited easily in XCode.

Load more pages in TTLauncherView

In my implementation of TTLauncherView, only loads the first page. Why?
I have 47 items in array, 47 items div 9 items by page, I should have 6 pages.
Thanks for helping.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSMutableString *jsonString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *results = [jsonString JSONValue];
NSArray *photos = [[results objectForKey:#"photosets"] objectForKey:#"photoset"];
launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];
launcherView.backgroundColor = [UIColor whiteColor];
launcherView.delegate = self;
launcherView.columnCount = 3;
launcherView.persistenceMode = TTLauncherPersistenceModeNone;
NSMutableArray *itemArray = [[NSMutableArray alloc] init];
for (NSDictionary *photo in photos)
{
NSString *iconURLString = [NSString stringWithFormat:#"http://farm%#.static.flickr.com/%#/%#_%#_s.jpg",
[photo objectForKey:#"farm"], [photo objectForKey:#"server"], [photo objectForKey:#"primary"], [photo objectForKey:#"secret"]];
NSDictionary *title = [photo objectForKey:#"title"];
NSString *itemTitle = [title objectForKey:#"_content"];
TTLauncherItem *itemMenu = [[[TTLauncherItem alloc] initWithTitle:itemTitle
image:iconURLString
URL:nil
canDelete:NO] autorelease];
[itemArray addObject:itemMenu];
}
launcherView.pages = [NSArray arrayWithObject: itemArray];
[self.view addSubview:launcherView];
}
As I recall, TTLauncherView doesn't break up the TTLauncherItem's into pages automatically. You need an array of arrays. All of the launcher item's in the first array will be on the first page, all the launcher item's in the second array will be on the second page etc. It has been a long time since I've used it, but I think that's how it worked.
My modified code with the hint of #Darren
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSMutableString *jsonString = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *results = [jsonString JSONValue];
NSArray *photos = [[results objectForKey:#"photosets"] objectForKey:#"photoset"];
NSMutableArray *itemArray = [[NSMutableArray alloc] init];
NSMutableArray *pageArray = [[NSMutableArray alloc] init];
NSNumber *countPage = [[NSNumber alloc] initWithInt:0];
for (NSDictionary *photo in photos)
{
NSString *iconURLString = [NSString stringWithFormat:#"http://farm%#.static.flickr.com/%#/%#_%#_s.jpg",
[photo objectForKey:#"farm"], [photo objectForKey:#"server"], [photo objectForKey:#"primary"], [photo objectForKey:#"secret"]];
NSString *photoCount = [photo objectForKey:#"photos"];
NSDictionary *title = [photo objectForKey:#"title"];
NSString *itemTitle = [title objectForKey:#"_content"];
TTLauncherItem *itemMenu = [[[TTLauncherItem alloc] initWithTitle:itemTitle
image:iconURLString
URL:nil
canDelete:NO] autorelease];
itemMenu.badgeValue = photoCount;
[itemArray addObject:itemMenu];
int value = [countPage intValue];
countPage = [NSNumber numberWithInt:value + 1];
if (countPage == [NSNumber numberWithInt:9]){
countPage = [NSNumber numberWithInt:0];
[pageArray addObject:itemArray];
itemArray = [[NSMutableArray alloc] init];
}
}
[pageArray addObject:itemArray];
launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];
launcherView.backgroundColor = [UIColor blackColor];
launcherView.delegate = self;
launcherView.columnCount = 3;
launcherView.persistenceMode = TTLauncherPersistenceModeNone;
launcherView.pages = pageArray;
[self.view addSubview:launcherView];
}

Array count Should be Show in table view

i want show my NSMutableArray Count in a UILabel ,,,,,,,,,,
can any one help me
NSMutableArray * anArray = [[NSMutableArray alloc] init];
UILabel * aLabel = [[UILabel alloc] init];
aLabel.text = [NSString stringWithFormat:#"%d", [anArray count]];

iPhone thinks textfields are empty after navigating through views (only on 8C148a)

Hey guys, I have the strangest bug in my application I'm developing.
The thing is I have a login screen with two textfields that I create, add as subviews and release, all done in viewDidLoad.
Then as the user has logged in and logs out again, the textfields appear as normal but when the login-method is called it thinks the textfields are empty!
I have also only found this bug on iOS 4.2.1 (8C148a)
Furthemore the log show "Received memory warning. Level=1" and sometimes "Level=2" and this might be related but I don't know.
Can anyone help me? I'm quite lost...
My viewDidLoad:
userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 85, 280, 30)];
userNameTextField.returnKeyType = UIReturnKeyNext;
userNameTextField.placeholder = #"Användarnamn:";
userNameTextField.layer.cornerRadius = 8;
userNameTextField.alpha = 0.9;
userNameTextField.opaque = YES;
userNameTextField.tag = 0;
userNameTextField.backgroundColor = [UIColor whiteColor];
userNameTextField.textAlignment = UITextAlignmentCenter;
userNameTextField.textAlignment = UIBaselineAdjustmentAlignBaselines;
userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
userNameTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
userNameTextField.adjustsFontSizeToFitWidth = FALSE;
[userNameTextField addTarget:self
action:#selector(textFieldDidReturn:)
forControlEvents:UIControlEventEditingDidEndOnExit];
passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 119, 280, 30)];
passwordTextField.returnKeyType = UIReturnKeyDone;
passwordTextField.placeholder = #"Lösenord:";
passwordTextField.secureTextEntry = YES;
passwordTextField.layer.cornerRadius = 8;
passwordTextField.alpha = 0.9;
passwordTextField.opaque = NO;
passwordTextField.tag = 1;
passwordTextField.backgroundColor = [UIColor whiteColor];
passwordTextField.textAlignment = UITextAlignmentCenter;
passwordTextField.textAlignment = UIBaselineAdjustmentAlignBaselines;
passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
passwordTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
passwordTextField.adjustsFontSizeToFitWidth = TRUE;
[passwordTextField addTarget:self
action:#selector(textFieldDidReturn:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[self.view addSubview:userNameTextField];
[self.view addSubview:passwordTextField];
userNameTextField.delegate = self;
passwordTextField.delegate = self;
[userNameTextField release];
[passwordTextField release];
I also use the following methods:
-(void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event {
[userNameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
[super touchesBegan:touches withEvent:event ];}
-(IBAction)textFieldDone:(id)sender {
[sender resignFirstResponder];}
-(BOOL)textFieldDidReturn:(UITextField *)textfield {
NSInteger nextTextFieldTag = textfield.tag + 1;
// Find next responding textfield
UIResponder *nextRespondingTextField = [textfield.superview viewWithTag:nextTextFieldTag];
if (nextRespondingTextField) {
[nextRespondingTextField becomeFirstResponder];
} else {
[self logInUser];
[textfield resignFirstResponder];
}
return NO;}
-(IBAction) logInUser {
// Popup alert
if (userNameTextField.text.length == 0 && passwordTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Vänligen ange användarnamn och lösenord." delegate:nil cancelButtonTitle:#"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else if (passwordTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Vänligen ange lösenord." delegate:nil cancelButtonTitle:#"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else if (userNameTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Vänligen ange användarnamn." delegate:nil cancelButtonTitle:#"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else {
PreschoolAppDelegate *globalAppDelegate = [[UIApplication sharedApplication] delegate];
// Set global username and password
globalAppDelegate.globalUserName = #"";
globalAppDelegate.globalPassword = #"";
globalAppDelegate.globalUserName = userNameTextField.text;
globalAppDelegate.globalPassword = passwordTextField.text;
// Clear variables
globalAppDelegate.globalFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalLastname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildSurname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildFullname = [[NSMutableString alloc] init];
globalAppDelegate.globalSelectedChild = [[NSMutableString alloc] init];
globalAppDelegate.globalIdString = [[NSMutableString alloc] init];
globalAppDelegate.globalChildIdString = [[NSMutableString alloc] init];
globalAppDelegate.globalSelectedChildId = [[NSString alloc] init];
globalAppDelegate.globalWipChildList = [[NSMutableArray alloc] init];
globalAppDelegate.globalChildIdList = [[NSMutableArray alloc] init];
globalAppDelegate.globalChildList = [[NSMutableArray alloc] init];
globalAppDelegate.globalWipChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalAbsenceArray = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalAbsenceDescription = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationDescription = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalVacationArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationWipChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationStartDate = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationEndDate = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationStartDates = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationEndDates = [[NSMutableArray alloc] init];
//
// Start the fetch of the data from the rest service
//
userClient = [[GetUserListRestClient alloc] init];
[userClient getUsers:self];
[pendingLogin startAnimating];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector (checkIfConnFinished:) userInfo:nil repeats:YES];
}}
I think the problems are in the property assignments like this:
globalAppDelegate.globalFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalWipChildList = [[NSMutableArray alloc] init];
This way your Strings and Arrays you created are never released. This caused the memory warnings. The good way is this:
NSMutableString *str = [[NSMutableString alloc] init];
globalAppDelegate.globalFirstname = str;
[str release];
Or a shorter but not as good solution:
globalAppDelegate.globalWipChildList = [[[NSMutableArray alloc] init] autorelease];
I hope I could help.