在Shinobi iOS Chart中切断了yAxis

时间:2017-06-01 20:10:39

标签: ios objective-c charts shinobi

https://www.dropbox.com/s/8fqez61k9jhnoa4/Screen%20Shot%202017-06-01%20at%201.04.25%20PM.png?dl=0

  • (void)createBurnoutChart {

    //创建图表(如果需要) if(burnoutChart == nil){     if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)

         burnoutChart = [[ShinobiChart alloc] initWithFrame:CGRectMake(0, 270, 768,725)];  // iPad
    else
    
        burnoutChart = [[ShinobiChart alloc] initWithFrame:CGRectMake(0, 165, 320,290)];  // iPhone
    
    // Set a different theme on the chart
    SChartMidnightTheme *midnight = [[SChartMidnightTheme alloc] init];
    [burnoutChart setTheme:midnight];
    
    //As the chart is a UIView, set its resizing mask to allow it to automatically resize when screen orientation changes.
    burnoutChart.autoresizingMask = ~UIViewAutoresizingNone;
    
    // Initialise the data source we will use for the chart
    burnoutDatasource = [[LineChartDataSource alloc] initWithFileName:LineChartSource_Burnout seriesCount:1];
    
    // Give the chart the data source
    burnoutChart.datasource = burnoutDatasource;
    
    // Create a date time axis to use as the x axis.
    SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] init];
    
    // Enable panning and zooming on the x-axis.
    xAxis.enableGesturePanning = YES;
    xAxis.enableGestureZooming = YES;
    xAxis.enableMomentumPanning = YES;
    xAxis.enableMomentumZooming = YES;
    xAxis.axisPositionValue = [NSNumber numberWithInt: 0];
    
    // And allow them to scroll past the default range
    xAxis.allowPanningOutOfMaxRange = YES;
    xAxis.allowPanningOutOfDefaultRange = YES;
    
    // Make the frequency of tick marks be one day
    SChartDateFrequency *freq = [[SChartDateFrequency alloc] initWithDay:1];
    xAxis.majorTickFrequency = freq;
    
    burnoutChart.xAxis = xAxis;
    
    //Create a number axis to use as the y axis.
    //TODO:Checkback
    NSNumber *lowRange = [[NSNumber alloc] initWithInteger:0];
    NSNumber *highRange = [[NSNumber alloc] initWithInteger:100];
    
    SChartNumberRange *yRange = [[SChartNumberRange alloc] initWithMinimum:lowRange andMaximum:highRange];
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] initWithRange:yRange ];
    
    //Enable panning and zooming on Y
    yAxis.enableGesturePanning = YES;
    yAxis.enableGestureZooming = YES;
    yAxis.enableMomentumPanning = YES;
    yAxis.enableMomentumZooming = YES;
    

    // yAxis.axisPositionValue = [NSNumber numberWithInt:0];

    // And allow them to scroll past the default range
    yAxis.allowPanningOutOfMaxRange = NO;
    yAxis.allowPanningOutOfDefaultRange = NO;
    
    
    burnoutChart.yAxis.defaultRange;
    burnoutChart.yAxis = yAxis;
    
    //Set the chart title
    burnoutChart.title = @"";
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        burnoutChart.titleLabel.font = [UIFont fontWithName:@"TrebuchetMS" size:27.0f];
    } else {
        burnoutChart.titleLabel.font = [UIFont fontWithName:@"TrebuchetMS" size:17.0f];
    }
    burnoutChart.titleLabel.textColor = [UIColor whiteColor];
    
    
    // If you have a trial version, you need to enter your licence key here:
    //    chart.licenseKey = @"";
    
    // Add the chart to the view controller
    [self.viewBurnoutChart addSubview:burnoutChart];
    

    }

    //确保我们获取最新数据 NSInteger lastScore = [burnoutDatasource reReadData]; [self vasBurnoutImage:lastScore]; [self vasBurnoutScore:lastScore]; [burnoutChart reloadData]; [burnoutChart redrawChartAndGL:YES];

    // *****重要的是重置可见部分..如果我得到了它 // [burnoutChart.xAxis resetZoomLevel]; }

图表显示效果很好,但是当涉及yAxis时,它会完全停在100限制范围内。我希望显示更多间隔,以便它看起来不会被切断。

1 个答案:

答案 0 :(得分:0)

有两种方法可以实现这一目标:

  • 如果您想手动设置轴的范围(与当前一样),则只需增加范围,例如不应影响刻度标签。
  • 如果您乐意让图表确定范围,那么您可以使用rangePaddingHigh属性来调整添加到计算范围内的填充量。

我希望有所帮助!