1
나는 핵심 플롯을 배우고 난 핵심 플롯 1.2 부비동 기능의 다음 그래프 그리기 왔어요 : 경우에도코어 플롯은 축을 그리지 않습니다. 이유는 무엇입니까?
당신이 볼 때, 축이 그려지지를 I 다음 스 니펫에서와 같이 내 축을 구성하십시오.
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [CPTColor blackColor];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
axisSet.xAxis.axisLineStyle = axisLineStyle;
axisSet.yAxis.axisLineStyle = axisLineStyle;
내 질문 : 왜 축이 표시되지 않습니까? CorePlot에서 어떻게 그릴 수 있습니까?.
-(void)viewDidLoad
{
[super viewDidLoad];
self.graph = [[CPTXYGraph alloc] initWithFrame:self.view.frame];
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
hostingView.hostedGraph = self.graph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-4) length:CPTDecimalFromFloat(8)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-2.0) length:CPTDecimalFromFloat(4.0)];
CPTScatterPlot *sinusPlot = [[CPTScatterPlot alloc] initWithFrame:self.graph.frame];
sinusPlot.dataSource = self;
sinusPlot.backgroundColor = [CPTColor whiteColor].cgColor;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [CPTColor blackColor];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
axisSet.xAxis.axisLineStyle = axisLineStyle;
axisSet.yAxis.axisLineStyle = axisLineStyle;
[self.graph addPlot:sinusPlot];
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return 101;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx
{
static double pi = 3.14159;
double x = pi*((((double)idx) - 51.0)/50.0);
if (fieldEnum == CPTScatterPlotFieldX)
return [NSNumber numberWithDouble:x];
else
return [NSNumber numberWithDouble:sin(x + ((x<0)?2*pi:0))];
}
코어 플롯 그래프의 일부분에 배경을 설정하는 데 'fill'을 사용하는 것이 더 좋습니다 :'self.graph.fill = [CPTFill fillWithColor : [CPTColor whiteColor]];' –
감사합니다. @EricSkroch 정보. 필자는 클래스 구조와 'fill' 속성을 정의하는 CPTBorderedLayer의 사용 방법을 모두 이해하기 위해이 클래스를 사용하고 있습니다. – naitoon