Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i have done something you want like this code. Sorry i don't make it clear code here but just pasting whole method what i am using here.</p> <p>i hope this may help what you want. Here i have implemented graph in new way that you can refresh it like tableview. just change values of array then call [graph reloadData];</p> <pre><code>- (void)constructScatterPlotForFeedback { // Create graph from theme [graph release]; graph = [[CPXYGraph alloc] initWithFrame:CGRectZero]; graph.delegate = self; CPTheme *theme = [CPTheme themeNamed:kCPPlainWhiteTheme]; [graph applyTheme:theme]; feedbackChart.hostedGraph = graph; [feedbackChart setBackgroundColor:[UIColor clearColor]]; graph.paddingLeft = 0.0; graph.paddingTop = 0.0; graph.paddingRight = 0.0; graph.paddingBottom = 0.0; graph.plotAreaFrame.paddingLeft = 5.0; graph.plotAreaFrame.paddingTop = 10.0; graph.plotAreaFrame.paddingRight = 10.0; graph.plotAreaFrame.paddingBottom = 10.0; NSTimeInterval oneHour = 60 * 60; // Setup plot space CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; plotSpace.allowsUserInteraction = YES; plotSpace.delegate = self; float xRange; xRange = [chartData count] + 1.0; if (xRange&gt;5) { xRange = 5.0; } plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(fiveHour*3)]; plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-20.0) length:CPDecimalFromFloat(40.0)]; CPLineStyle *gridline = [CPLineStyle lineStyle]; gridline.lineColor = [CPColor grayColor]; gridline.lineWidth = 1.0f; // Axes CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; CPXYAxis *x = axisSet.xAxis; // x.orthogonalCoordinateDecimal = CPDecimalFromString(@"0"); x.majorIntervalLength = CPDecimalFromFloat(fiveHour); //x.majorIntervalLength = CPDecimalFromFloat(10.0); //x.majorIntervalLength = CPDecimalFromString(@"10"); x.minorTicksPerInterval = 0; x.labelOffset=0; // x.labelingPolicy = CPAxisLabelingPolicyNone; NSDate *refDate = [NSDate date]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; // dateFormatter.dateStyle = kCFTimeZoneNameStyleShortGeneric; dateFormatter.dateFormat = @"HH:mm:ss"; // dateFormatter.dateStyle = kCFDateFormatterShortStyle; CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc] init WithDateFormatter:dateFormatter] autorelease]; timeFormatter.referenceDate = refDate; x.labelFormatter = timeFormatter; //NSLog(@"refence date : %@", timeFormatter); CPXYAxis *y = axisSet.yAxis; y.minorTicksPerInterval = 0; y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0.0"); y.majorIntervalLength = CPDecimalFromString(@"5"); y.majorGridLineStyle = nil; //y.visibleRect y.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-20.0f) length:CPDecimalFromFloat(40.0f)]; CPConstraints yConstraints = {CPConstraintNone, CPConstraintFixed}; y.isFloatingAxis=YES; y.constraints=yConstraints; // Create a green plot area CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease]; dataSourceLinePlot.identifier = @"FeedBack Plot"; dataSourceLinePlot.dataLineStyle.lineWidth = 3.f; dataSourceLinePlot.dataLineStyle.lineColor = [CPColor blackColor]; dataSourceLinePlot.dataLineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:1.0f], [NSNumber numberWithFloat:1.0f], nil]; dataSourceLinePlot.dataSource = self; // Animate in the new plot, as an example dataSourceLinePlot.opacity = 0.0f; dataSourceLinePlot.cachePrecision = CPPlotCachePrecisionDecimal; CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeInAnimation.duration = 1.0f; fadeInAnimation.removedOnCompletion = NO; fadeInAnimation.fillMode = kCAFillModeForwards; fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0]; [dataSourceLinePlot addAnimation:fadeInAnimation forKey:@"animateOpacity"]; CPColor *areaColor1 = [CPColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8]; CPGradient *areaGradient1 = [CPGradient gradientWithBeginningColor:areaColor1 endingColor:[CPColor clearColor]]; areaGradient1.angle = -90.0f; NSUInteger i; [graph addPlot:dataSourceLinePlot]; NSMutableArray *contentArray1 = [NSMutableArray arrayWithCapacity:100]; NSMutableArray *customTickLocations = [[NSMutableArray alloc] init]; NSMutableArray *xAxisLabels = [[NSMutableArray alloc] init]; for ( i = 0; i &lt; [chartData count]; i++ ) { //for ( i = 0; i &lt; 10; i++ ) { [customTickLocations addObject:[NSDecimalNumber numberWithInt:i]]; [xAxisLabels addObject:[NSString stringWithFormat:@"%0.1f", 5.0 * i]]; Pulse *objPulse1 = (Pulse *)[chartData objectAtIndex:i]; //id x = [NSNumber numberWithFloat:i*fiveHour]; id x = [NSNumber numberWithFloat:i]; id y = [NSNumber numberWithFloat:[objPulse1.feedBack floatValue]]; NSLog(@"point of gragh for Performance x:%@, y : %@ ", x, y); [contentArray1 addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]]; } NSLog(@"Axis lable count : %d", [xAxisLabels count]); NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[chartData count]]; NSUInteger labelLocation = 0; for (NSNumber *tickLocation in customTickLocations) { NSLog(@"&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; tick location"); CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle]; newLabel.tickLocation = [tickLocation decimalValue]; newLabel.offset = x.labelOffset + x.majorTickLength - 5.0f; // newLabel.rotation = M_PI/(2); newLabel.rotation = 0; [customLabels addObject:newLabel]; [newLabel release]; } x.axisLabels = [NSSet setWithArray:customLabels]; // [arrScatter removeAllObjects]; arrScatter = contentArray1; [arrScatter retain]; // NSLog(@"&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; :%d", [arrScatter count]); } -(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot { if ( [(NSString *)plot.identifier isEqualToString:@"FeedBack Plot"] ) { return [chartData count]; // return 10; } return 0; } -(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:( NSUInteger)index { switch ( fieldEnum ) { case CPScatterPlotFieldX: return (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index*fiveHour]; case CPScatterPlotFieldY: { Pulse *objPulse1 = (Pulse *)[chartData objectAtIndex:index]; return [NSNumber numberWithFloat:[objPulse1.feedBack floatValue]]; } } return nil; } -(CGPoint)plotSpace:(CPPlotSpace *)space willDisplaceBy:(CGPoint)displacement { // NSLog(@"&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; : %f", displacement.x); return CGPointMake(displacement.x, 0); } /* -(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex: (NSUInteger)index { NSDecimalNumber *num = nil; if ( [(NSString *)plot.identifier isEqualToString:@"FeedBack Plot"] ) { if ( [arrScatter count] != 0) { num = [[arrScatter objectAtIndex:index] valueForKey:(fieldEnum == CPScatterPlotFieldX ? @"x" : @"y")]; } } return num; } */ -(CPLayer *)dataLabelForPlot:(CPPlot *)plot recordIndex:(NSUInteger)index { Pulse *objPulse1 = (Pulse *)[chartData objectAtIndex:index]; float value = [objPulse1.feedBack floatValue]; //CPTextLayer *textLayer = [[CPTextLayer alloc] initWithText:[NSString stringWithFormat:@"%d", value]]; CPTextStyle *textStyle = [CPTextStyle textStyle]; textStyle.color = [CPColor blackColor]; CPTextLayer *textLayer = [[CPTextLayer alloc] initWithText:[NSString stringWithFormat:@"%0.1f", value] style:textStyle]; return textLayer; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload