2017-09-12 7 views
9

CorePlot을 사용하여 MacOS 응용 프로그램에 간단한 선 그래프를 그립니다.CorePlot LineGraph - 값을보기 위해 그래프를 가리 키거나 클릭하십시오 - macOS

CPTXYGraph *newGraph = [[CPTXYGraph alloc] initWithFrame:CGRectZero]; 

CPTTheme *theme  = [CPTTheme themeNamed:kCPTDarkGradientTheme]; 
[newGraph applyTheme:theme]; 
self.graph = newGraph; 
self.hostView.hostedGraph = newGraph; 

newGraph.plotAreaFrame.paddingTop = 10.0; 
newGraph.plotAreaFrame.paddingBottom = 30.0; 
newGraph.plotAreaFrame.paddingLeft = 40.0; 
newGraph.plotAreaFrame.paddingRight = 10.0; 

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)newGraph.defaultPlotSpace; 
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:@(1.0) length:[NSNumber numberWithUnsignedInteger:[dataArray count]-1]]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@102.0]; 
    plotSpace.allowsUserInteraction = YES; 

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)newGraph.axisSet; 
    CPTXYAxis *x   = axisSet.xAxis; 
    //x.majorIntervalLength = @1; 
    x.majorIntervalLength = [NSNumber numberWithInt:numberOfIntervalsX]; 
    x.orthogonalPosition = @(0); 
    x.minorTicksPerInterval = 0; 
    x.labelOffset = 0; 

    CPTXYAxis *y = axisSet.yAxis; 
    y.majorIntervalLength = @5; 
    y.minorTicksPerInterval = 0; 
    y.orthogonalPosition = @(1.0); 
    y.labelOffset = 0.0; 

CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init]; 
    CPTMutableLineStyle *lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy]; 
    lineStyle.lineWidth    = 2.; 
    lineStyle.lineColor    = [CPTColor greenColor]; 
    dataSourceLinePlot.dataLineStyle = lineStyle; 


    dataSourceLinePlot.dataSource = self; 
    [newGraph addPlot:dataSourceLinePlot]; 

나는 호버/클릭으로 값을 보는 것이 기본 동작이지만 기대하지 않을 것으로 예상했다. 포럼을 검색해 보았지만 행운은 없습니다. 나는 그것이 정말로 똑바로 될 것 인 것을 당연하다고 생각하고있다. 내가 뭔가를 놓치고 있는지 확실하지 않습니다.

답변

4

내가 아는 한, 당신은 인상적이다. 데이터 값 오버레이가 내장되어 있지 않다. 그러나 직접 만들 수 있습니다. CorePlot에는 indexOfVisiblePointClosestToPlotAreaPoint: 함수가있어 차트에 레이블 값을 추가하는 데 필요한 참조를 제공해야합니다.

  • (NSUInteger) indexOfVisiblePointClosestToPlotAreaPoint : 눈에 보이는 지점이없는 경우

은 가장 가까운 지점의 인덱스 또는 NSNotFound를 돌려줍니다.

그런 다음 당신은 당신의 그래프 hostingview의 하위 클래스를 마우스 좌표를 캡처하는 마우스 이동 이벤트를 구현하고 거기에서 당신이 포인트를 표시하는 방법을 선택하려면 어떤 논리 할 수 ​​있습니다.

구현하기가 특히 쉽지만 적어도 직선적 인 의미는 아닙니다. 도움이되기를 바랍니다!

참고 :

http://core-plot.github.io/MacOS/interface_c_p_t_scatter_plot.html#a57eacc8261a4d4a1399f1196be786cff https://stackoverflow.com/a/21819342/357288