rajeev karamchedu

Technology and Professional Services Director, currently part of a very exciting and talented team of technology/data management solution provider, IronBrick

2 responses to “Blogroll Cloud”

  1. Danniel

    Hello, if you can do blogroll cloud, please send me an e-mail. Have a nice day!

  2. Debabrata Biswas

    Dear Sir,
    I have drawn pie chart using Core Plot library and data from Sqlite database. But I am not able to add label to each slice of pie. I am mentioning my code here. please help me out.. Its very urgent. From database I am fetching two field amount and category, I want to add amount as label of each slice of pie and below of chart I want to mention category name with slice color. How to do it… Thanks in advance.. Below Is my code….

    #import “PieChart_SampleViewController.h”

    static sqlite3 *database = nil;

    NSMutableArray *showChart = nil;
    NSMutableArray *arrayChart = nil;

    double chartCost;
    NSString *chartCategory;

    NSInteger day1, year1;
    NSString *month;

    static sqlite3_stmt *todayStmt = nil;
    static sqlite3_stmt *monthStmt = nil;
    static sqlite3_stmt *yearStmt = nil;

    @implementation PieChart_SampleViewController

    @synthesize graph,pieData,layerHost;
    @synthesize segmentControl;

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor lightGrayColor];

    SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *dbPath = [appDelegate getDBPath];
    NSLog(@”%@”,dbPath);

    showChart = [[NSMutableArray alloc] init];

    NSDate* date = [NSDate date];
    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"yyyy-MMMM-dd-ccc"];
    NSString *datestr = [formatter stringFromDate:date];
    NSArray *date1 = [datestr componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-"]];

    NSString *year = [date1 objectAtIndex:0];
    month = [[NSString alloc] initWithString:[date1 objectAtIndex:1]];
    NSString *day = [date1 objectAtIndex:2];
    NSString *week_day = [date1 objectAtIndex:3];

    day1 = [day intValue];
    year1 = [year intValue];

    [self Today_Report:day1 tmonth:month tyear:year1];
    [self constructPieChart];

    NSLog(@”Current day In Number:::%@”,day);
    NSLog(@”Current day1:::%@”,week_day);
    NSLog(@”Current Month:::%@”,month);
    NSLog(@”Current Year:::%d”,year1);

    [self.segmentControl addTarget:self action:@selector(SegmentControlIndexChanged:) forControlEvents:UIControlEventValueChanged];

    }

    -(void)constructPieChart {

    graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
    layerHost.hostedLayer = graph;
    graph.paddingLeft = 10.0;
    graph.paddingTop = 10.0;
    graph.paddingRight = 10.0;
    graph.paddingBottom = 100.0;

    CPPieChart *pieChart = [[CPPieChart alloc] init];
    pieChart.dataSource = self;
    pieChart.pieRadius = 100.0;
    pieChart.identifier = @”PieChart”;
    pieChart.startAngle = M_PI_4;

    pieChart.sliceDirection = CPPieDirectionClockwise;
    self.pieData = arrayChart;
    CPTheme *theme = [CPTheme themeNamed:kCPSlateTheme];
    [graph applyTheme:theme];
    [graph addPlot:pieChart];
    [pieChart release];

    // For Label on each slice of pie
    int k=-135;
    int j=50;

    for (int i=0; i<[arrayChart count];i++)
    {
    k=k+50;
    k=j+50;
    CPTextLayer *layerdarkgrayotfinalfi=nil;
    if (!layerdarkgrayotfinalfi)
    {
    NSString *test=[NSString stringWithFormat:@"%@",[arrayChart objectAtIndex:i]];
    NSLog(@"Label Test:%@",test);
    layerdarkgrayotfinalfi= [[[CPTextLayer alloc] initWithText:test]autorelease];
    layerdarkgrayotfinalfi.bounds = CGRectMake(0, 0, 20, 10);
    layerdarkgrayotfinalfi.position = CGPointMake(k, j);
    //layerdarkgrayotfinalfi.textStyle=whiteText1;
    [layerHost.hostedLayer addSublayer:layerdarkgrayotfinalfi];

    }

    }

    }

    - (void)SegmentControlIndexChanged:(id)sender{

    switch (self.segmentControl.selectedSegmentIndex) {
    case 0:
    [self Today_Report:day1 tmonth:month tyear:year1];
    [self constructPieChart];
    break;
    case 1:
    NSLog(@"Hello Week");

    break;
    case 2:
    NSLog(@"Hello Month %@",month);

    [self Monthwise_Report:month Year:year1];
    [self constructPieChart];
    break;
    case 3:
    [self YearWise_Report:year1];
    [self constructPieChart];
    break;
    default:
    break;
    }
    }

    - (void)Today_Report:(NSInteger)today tmonth:(NSString *)tmth tyear:(NSInteger)tyr{

    //[showReport removeAllObjects];
    [arrayChart removeAllObjects];

    NSInteger tday = today;
    NSString *tmonth = tmth;
    NSInteger tyear = tyr;

    NSLog(@"Today :::%d",tday);

    SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *dbPath = [appDelegate getDBPath];
    NSLog(@"%@",dbPath);

    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
    {

    if (todayStmt == nil)
    {

    const char *queryString = "select sum(cost), category from expense where day = ? and month = ? and year = ? group by category";

    int return_value =sqlite3_prepare_v2(database, queryString, -1, &todayStmt, NULL);

    if (return_value == SQLITE_OK)
    {

    sqlite3_bind_int(todayStmt,1, tday);
    sqlite3_bind_text(todayStmt, 2, [tmonth UTF8String], -1 ,SQLITE_TRANSIENT);
    sqlite3_bind_int(todayStmt, 3, tyear);

    arrayChart = [[NSMutableArray alloc] init];

    while(sqlite3_step(todayStmt) == SQLITE_ROW) {

    showReporttemp = [[Report alloc] init];

    showReporttemp.cost = (double)sqlite3_column_double(todayStmt, 0);
    showReporttemp.category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(todayStmt, 1)];

    NSLog(@"Category name :%@",showReporttemp.category);
    NSLog(@"Cost %f",showReporttemp.cost);

    [showChart addObject:showReporttemp];
    NSLog(@"Object no %d", [showChart count]);
    chartCost = showReporttemp.cost;
    [arrayChart addObject:[NSNumber numberWithDouble:chartCost]];

    }
    }
    }
    else {
    NSAssert1(0, @"Prepare statement failed with message %s", sqlite3_errmsg(database));

    }
    sqlite3_reset(todayStmt);
    }

    todayStmt = nil;
    sqlite3_close(database);
    //[tableView reloadData];

    }

    - (void)WeekWise_Report:(NSString *)wdate Catg:(NSString *)cat{

    }

    - (void)Monthwise_Report:(NSString *)mon Year:(NSInteger)yr{

    //[showReport removeAllObjects];
    [arrayChart removeAllObjects];

    NSString *getmonth = mon;
    NSInteger year = yr;

    NSLog(@"Current Month and Year %@,%d",mon,year);

    SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *dbPath = [appDelegate getDBPath];
    NSLog(@"%@",dbPath);

    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
    {

    if (monthStmt == nil)
    {

    const char *queryString = "select sum(cost), category from expense where month = ? and year = ? group by category";

    int return_value =sqlite3_prepare_v2(database, queryString, -1, &monthStmt, NULL);

    if (return_value == SQLITE_OK)
    {

    sqlite3_bind_text(monthStmt, 1 , [getmonth UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_int(monthStmt,2, year);

    arrayChart = [[NSMutableArray alloc] init];

    while(sqlite3_step(monthStmt) == SQLITE_ROW) {

    NSLog(@"Fetching Started");
    showReporttemp = [[Report alloc] init];

    showReporttemp.cost = (double)sqlite3_column_double(monthStmt, 0);
    showReporttemp.category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(monthStmt, 1)];

    NSLog(@"Catagory name in chart page :%@",showReporttemp.category);
    NSLog(@"Cost %.02f",showReporttemp.cost);
    chartCost = showReporttemp.cost;
    NSLog(@"Chart Cost:%.02f",chartCost);
    [showChart addObject:showReporttemp];
    NSLog(@"Object no %d", [showChart count]);
    [arrayChart addObject:[NSNumber numberWithDouble:chartCost]];

    }
    }
    }
    else {
    NSAssert1(0, @"Prepare statement failed with message %s", sqlite3_errmsg(database));

    }
    sqlite3_reset(monthStmt);
    }
    monthStmt = nil;
    sqlite3_close(database);
    //[tableView reloadData];

    }

    - (void)YearWise_Report:(NSInteger)rpyear{

    //[showReport removeAllObjects];
    [arrayChart removeAllObjects];

    NSInteger year = rpyear;

    NSLog(@"Current Year:::%d",year);

    SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *dbPath = [appDelegate getDBPath];
    NSLog(@"%@",dbPath);

    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
    {

    if (yearStmt == nil)
    {

    const char *queryString = "select sum(cost), category from expense where year = ? group by category";

    int return_value =sqlite3_prepare_v2(database, queryString, -1, &yearStmt, NULL);

    if (return_value == SQLITE_OK)
    {
    NSLog(@"Execution 5 starts from here");

    sqlite3_bind_int(yearStmt,1, year);
    arrayChart = [[NSMutableArray alloc] init];

    while(sqlite3_step(yearStmt) == SQLITE_ROW) {

    NSLog(@"Fetching Started");
    showReporttemp = [[Report alloc] init];

    showReporttemp.cost = (double)sqlite3_column_double(yearStmt, 0);
    showReporttemp.category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(yearStmt, 1)];

    NSLog(@"Category name :%@",showReporttemp.category);
    NSLog(@"Cost %f",showReporttemp.cost);

    [showChart addObject:showReporttemp];
    NSLog(@"Object no %d", [showChart count]);
    chartCost = showReporttemp.cost;
    [arrayChart addObject:[NSNumber numberWithDouble:chartCost]];

    }
    }
    }
    else {
    NSAssert1(0, @"Prepare statement failed with message %s", sqlite3_errmsg(database));

    }
    sqlite3_reset(yearStmt);
    }

    yearStmt = nil;
    sqlite3_close(database);
    //[tableView reloadData];

    }

    -(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot
    {
    return [self.pieData count];

    }

    -(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
    {
    return [self.pieData objectAtIndex:index];
    }

    /*
    -(CPFill *)sliceFillForPieChart:(CPPieChart *)pieChart recordIndex:(NSUInteger)index {

    CPFill * fill = [CPFill fillWithGradient:[CPGradient rainbowGradient]];
    return fill;

    }*/

    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    /*- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }*/

    - (void)dealloc {
    [pieData release];
    [graph release];
    [segmentControl release];
    [super dealloc];
    }

    @end

Leave a Reply