graph.plotAreaFrame.paddingLeft +=5;
graph.plotAreaFrame.paddingTop +=5;
graph.plotAreaFrame.paddingRight +=5;
graph.plotAreaFrame.paddingBottom +=17.5;
[selfsetAllowPinchScaling:NO];//禁止缩放
plotSpace.yRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(1)];
plotSpace.globalYRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(1)];
plotSpace.xRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(1)length:CPTDecimalFromFloat(1)];
plotSpace.globalXRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(2)];
x.axisLabels = [self buildLabelTitle];
x.labelingPolicy = CPTAxisLabelingPolicyNone;//当设置这个Policy之后,坐标轴label及背景线tick都需要自己绘制,否则显示为空,请不要过度惊慌
x.minorTickLocations = [NSSetsetWithArray:locationLabels];
- (NSMutableSet*)buildLabelTitle
{
NSMutableSet *newAxisLabels = [NSMutableSetset];
CPTMutableTextStyle *textStyleB = [CPTMutableTextStyletextStyle];
textStyleB.color = [CPTColorcolorWithComponentRed:CPTFloat((float)0x09/0xFF)green:CPTFloat((float)0x31/0xFF)blue:CPTFloat((float)0x4A/0xFF)alpha:CPTFloat(1.0)];
int n = 1;
for ( NSUInteger i =30; i > 0; i--)
{
CPTAxisLabel *newLabel = [[CPTAxisLabelalloc] initWithText:@“这里是内容”
textStyle:textStyleB];
newLabel.tickLocation =CPTDecimalFromUnsignedInteger(n++);
newLabel.offset = 5;
[locationLabels addObject:[NSNumber numberWithFloat:(n-1) -0.25]];
[locationLabels addObject:[NSNumber numberWithFloat:(n-1) +0.25]];
[newAxisLabels addObject:newLabel];
[newLabel release];
}
return newAxisLabels;
}
[[bar1graph] reloadData];
[m_SO2OnlineCaddObject:[NSMutableDictionarydictionaryWithObjectsAndKeys:x, @"x", y,@"y", nil]];
if (tmpY> MAX_data)
{
MAX_data = tmpY;
}
if ([(NSString*)plot.identifierisEqualToString:kBar1])
{
switch (fieldEnum)
{
caseCPTBarPlotFieldBarLocation:
number = [[[m_SO2OnlineCobjectAtIndex:index] valueForKey:@"x"]doubleValue];
break;
caseCPTBarPlotFieldBarTip:
number = [[[m_SO2OnlineCobjectAtIndex:index] valueForKey:@"y"]doubleValue]/ MAX_data;
break;
default:
break;
}
}
这里要记录MAX_data的原因是这里最好使用真实数据的相对数据,否则当数据值很大的时候会消耗corePlot的性能导致图形加载很慢。
[selfperformSelector:@selector(initPlotData)withObject:nilafterDelay:0.2];
NSDateComponents* comps = [[NSDateComponentsalloc]init];
[comps setDay:-i];
NSDate *newDate = [[NSCalendarcurrentCalendar] dateByAddingComponents:compstoDate:[NSDate date]options:0];
--------------------------------------------------------
for (UIView* sbViewin scrvBg.subviews)
{
[sbView removeFromSuperview];
}
这里还有个获得subView的小技巧:
[subView setTag:300];
subView = [self.viewviewWithTag:300]
我这里能给出的经验就是,alloc的对象应该立即release。如果该对象不能立即release,必须保证alloc和release必须配对调用,特别要留意那些可以多次调用且包含alloc却未被及时release的函数。四个字概括“非常危险”!
self.my_arr =[[NSArray alloc]init]; ---------- 错误!
NSArray *tmpArr = [[NSArray alloc]init];
self.my = tmpArr;
[tmpArr release]; ---------- 正确