2012-08-08 138 views
0

我有一個問題,顯示正確的情節。我使用了RealTimePlot的一些代碼(http://code.google.com/p/core-plot/source/browse/examples/CorePlotGallery/src/plots/RealTimePlot.m)。我不知道爲什麼情節會逆轉。有照片顯示問題。核心情節 - 反轉劇情和標籤

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self generateDataSamples]; 

    CPTGraphHostingView *hostingView = [[[CPTGraphHostingView alloc] initWithFrame:self.view.bounds] autorelease]; 
    [self.view addSubview:hostingView]; 

    graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds]; 
    hostingView.hostedGraph = graph; 


    CPTTheme *theme = [CPTTheme themeNamed:kCPTSlateTheme]; 
    [graph applyTheme:theme]; 

    graph.plotAreaFrame.paddingTop = 15; 
    graph.plotAreaFrame.paddingRight = 40; 
    graph.plotAreaFrame.paddingBottom = 15; 
    graph.plotAreaFrame.paddingLeft = 55; 

    // 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; 
    [labelFormatter release]; 

    // 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] autorelease]; 
    dataSourceLinePlot.identifier = kPlotIdentifier; 
    dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDouble; 

    CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease]; 
    lineStyle.lineWidth = 3.0; 
    lineStyle.lineColor = [CPTColor greenColor]; 
    dataSourceLinePlot.dataLineStyle = lineStyle; 

    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(250)]; 
} 

reversed plot

回答

0

iOS的應用CPTGraphHostingView翻轉變換到託管圖,從而核心情節可以分享繪畫的iOS和Mac之間的代碼。確保託管視圖及其所有超級視圖都使用其默認轉換。

+0

非常感謝。核心情節圖被託管在CPTGraphHostingView中。我更改爲UIView,現在可以。也許你能幫助我用實時數據提供令人耳目一新的情節嗎?有http://stackoverflow.com/questions/11869179/core-plot-realtime-plot-does-not-automatically-refresh – syntagma 2012-08-09 07:39:18

0

嘗試只是增加hostingView到self.view之前添加

[hostingView setTransform:CGAffineTransformMakeScale(1,-1)]; 

我使用iOS7的Xcode 5.0,這解決了這個問題。