Core Plot
라이브러리에 표시된 예제를 기반으로 프로젝트에서 다시 구현하려고했습니다.코어 플롯이 선을 그릴 수 없습니다
y axis
을 업데이트하고 심볼을 추가하고 라벨을 그릴 수 있습니다. 그러나 나는 그 라인을 완전히 그릴 수 없습니다.
CPTMutableLineStyle
목적은 내 그래프에 선 스타일을 추가하는 방법입니다 정확하게는 instantied 올바르게 CPTGraph
객체에 살고 있고하는 것 같지만 그래프 여기
에 렌더링되지 않습니다
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle]; // [dataSourceLinePlot.dataLineStyle mutableCopy];
lineStyle.lineWidth = 3.0;
lineStyle.lineColor = [CPTColor greenColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
다음은 전체 클래스 코드입니다.
#import "TUTSimpleScatterPlot.h"
const double kFrameRate = 5.0; // frames per second
const double kAlpha = 0.15; // smoothing constant
const NSUInteger kMaxDataPoints = 21;
NSString *kPlotIdentifier = @"Data Source Plot";
@implementation TUTSimpleScatterPlot
// Initialise the scatter plot in the provided hosting view with the provided data.
// The data array should contain NSValue objects each representing a CGPoint.
-(id)initWithHostingView:(CPTGraphHostingView *)hostingView andData:(NSMutableArray *)data
{
self = [super init];
if (self != nil) {
self.hostingView = hostingView;
self.graphData = data;
self.graph = nil;
}
return self;
}
-(void)initialisePlot
{
self.graphData = [NSMutableArray array];
CGRect bounds = self.hostingView.bounds;
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds] ;
[self.hostingView setHostedGraph:graph];
graph.title = @"Measure";
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor grayColor];
textStyle.fontName = @"Helvetica-Bold";
textStyle.fontSize = round(bounds.size.height/(CGFloat)20.0);
graph.titleTextStyle = textStyle;
graph.titleDisplacement = CGPointMake(0.0f, round(bounds.size.height/(CGFloat)18.0)); // Ensure that title displacement falls on an integral pixel
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
CGFloat boundsPadding = round(bounds.size.width/(CGFloat)20.0); // Ensure that padding falls on an integral pixel
graph.paddingLeft = boundsPadding;
if (graph.titleDisplacement.y > 0.0) {
graph.paddingTop = graph.titleDisplacement.y * 2;
}
else {
graph.paddingTop = boundsPadding;
}
graph.paddingRight = boundsPadding;
graph.paddingBottom = boundsPadding;
graph.plotAreaFrame.paddingTop = 15.0;
graph.plotAreaFrame.paddingRight = 15.0;
graph.plotAreaFrame.paddingBottom = 55.0;
graph.plotAreaFrame.paddingLeft = 55.0;
// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.2] colorWithAlphaComponent:0.75];
CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];
// Axes
// X axis
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
x.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
x.majorGridLineStyle = majorGridLineStyle;
x.minorGridLineStyle = minorGridLineStyle;
x.minorTicksPerInterval = 9;
x.title = @"X Axis";
x.titleOffset = 35.0;
NSNumberFormatter *labelFormatter = [[NSNumberFormatter alloc] init];
labelFormatter.numberStyle = NSNumberFormatterNoStyle;
x.labelFormatter = labelFormatter;
// Y axis
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.minorTicksPerInterval = 3;
y.labelOffset = 5.0;
y.title = @"Y Axis";
y.titleOffset = 30.0;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
// Rotate the labels by 45 degrees, just to show it can be done.
x.labelRotation = M_PI * 0.25;
// Create the plot
CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init];
dataSourceLinePlot.identifier = kPlotIdentifier;
dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDouble;
// dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationCurved;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle]; // [dataSourceLinePlot.dataLineStyle mutableCopy];
lineStyle.lineWidth = 3.0;
lineStyle.lineColor = [CPTColor greenColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
CPTMutableLineStyle *symbolLineStyle = [CPTMutableLineStyle lineStyle];
symbolLineStyle.lineColor = [[CPTColor blackColor] colorWithAlphaComponent:0.5];
CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.fill = [CPTFill fillWithColor:[[CPTColor blueColor] colorWithAlphaComponent:0.5]];
plotSymbol.lineStyle = symbolLineStyle;
plotSymbol.size = CGSizeMake(10.0, 10.0);
dataSourceLinePlot.plotSymbol = plotSymbol;
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];
// Plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(kMaxDataPoints - 1)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(1)];
self.graph = graph;
self.dataTimer = [NSTimer timerWithTimeInterval:1.0/kFrameRate
target:self
selector:@selector(newData:)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.dataTimer forMode:NSDefaultRunLoopMode];
}
#pragma mark -
#pragma mark Timer callback
-(void)newData:(NSTimer *)theTimer
{
CPTGraph *theGraph = self.graph;
CPTPlot *thePlot = [theGraph plotWithIdentifier:kPlotIdentifier];
if (thePlot) {
// if (self.graphData.count >= kMaxDataPoints - 5) {
// [self.graphData removeObjectAtIndex:0];
// [thePlot deleteDataInIndexRange:NSMakeRange(0, 1)];
// }
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)theGraph.defaultPlotSpace;
NSUInteger location = (_currentIndex >= kMaxDataPoints ? _currentIndex - kMaxDataPoints + 5 : 0);
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(location)
length:CPTDecimalFromUnsignedInteger(kMaxDataPoints - 1)];
_currentIndex++;
NSNumber * num;
if (_currentIndex == 1) {
num = [NSNumber numberWithDouble: 5 + (arc4random() % 15) ];
} else {
NSLog(@"lastVal: %d", [[self.graphData lastObject] intValue]);
float low_bound = (1 - kAlpha) * [[self.graphData lastObject] floatValue];
float high_bound = (1.01 + kAlpha) * [[self.graphData lastObject] floatValue];
float random = (((float)arc4random()/0x100000000)*(high_bound-low_bound)+low_bound);
NSLog(@"random: %f", random);
num = [NSNumber numberWithDouble:random];
}
// Update y range if necessary
if (_currentIndex < kMaxDataPoints) {
int maxValue = -1;
for (int i = self.graphData.count -1 ; (i >= 0); i--) {
if ([[self.graphData objectAtIndex:i] intValue] > maxValue) {
maxValue = [[self.graphData objectAtIndex:i] intValue];
}
}
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(maxValue + 1)];
} else if (_currentIndex >= kMaxDataPoints) {
int maxValue = -1;
for (int i = self.graphData.count -1 ; (i >= self.graphData.count - kMaxDataPoints + 2); i--) {
if ([[self.graphData objectAtIndex:i] intValue] > maxValue) {
maxValue = [[self.graphData objectAtIndex:i] intValue];
}
}
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(maxValue + 1)];
}
[self.graphData addObject:num];
[thePlot insertDataAtIndex:self.graphData.count - 1 numberOfRecords:1];
}
}
#pragma mark -
#pragma mark Plot Data Source Methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return [self.graphData count];
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSNumber *num = nil;
switch (fieldEnum) {
case CPTScatterPlotFieldX:
num = [NSNumber numberWithUnsignedInteger:index + _currentIndex - self.graphData.count];
break;
case CPTScatterPlotFieldY:
num = [self.graphData objectAtIndex:index];
break;
default:
break;
}
return num;
}
@end
아이디어가 있으십니까? 팁? 해킹? 내 프로젝트에서
UPDATE 1
나는 도서관의 1.2
버전을 사용했다. 회귀하려고 시도한 후 1.0
버전과 줄이 표시됩니다. 마지막 버전에서 작업하도록 프로젝트를 변환하는 방법에 대한 아이디어가 있습니까? pod 'CorePlot', '~> 1.2'
에 pod 'CorePlot'
에서 Podfile
변경
는 UPDATE 2 *
다른 것 같다. 내 라인을 제대로 그려 ...
테스트 프로젝트를 업로드 할 수 있습니까 (사용하고있는 coreplot 1.2 소스/바이너리 포함)? –
@ A-Live는 coreplot 버전 1.2로 돌아가는 프로젝트입니다. http://fs04n5.sendspace.com/dl/84360c8cf7bf0689f79038369bd5dbec/5174f0d01c2e7eee/izqmod/BTLE_Transfer.zip –
그것은 이상하게도 프로젝트가없는 나를 위해 선을 그립니다 변경 (음, 도서관 검색 경로를 다뤄야 만했습니다.) : http://db.tt/JAEdYWIF 또한 iPad 3에서 작동했습니다. 아, 그리고'포드 설치 '를했습니다. –