Я делаю график для своего приложения для iOS, используя библиотеку Core Plot
Однако на моих осях не отображаются цифры или метки:
Вот мой viewDidLoad
метод:
- (void)viewDidLoad
{
[super viewDidLoad];
//[self generateExponentialDataSamples];
[self generateGraphDataSamples];
CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:hostingView];
// Create graph from theme
CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
[graph applyTheme:theme];
graph.paddingLeft = 30.0;
graph.paddingTop = 30.0;
graph.paddingRight = 30.0;
graph.paddingBottom = 30.0;
hostingView.hostedGraph = graph;
// Title
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor greenColor];
textStyle.fontSize = 18.0f;
textStyle.fontName = @"Helvetica";
graph.title = @"My Progress";
graph.titleTextStyle = textStyle;
graph.titleDisplacement = CGPointMake(0.0f, -20.0f);
double xAxisStart = 0.0;
double xAxisLength = MAX_X_VALUE;
double yAxisStart = 0.0;
//double yAxisLength = [[samples valueForKeyPath:@"@max.Y_VAL"]doubleValue];
double yAxisLength = 10;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(xAxisStart) length:CPTDecimalFromDouble(xAxisLength)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(yAxisStart) length:CPTDecimalFromDouble(yAxisLength)];
//Axis
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.minorTicksPerInterval = 0; //the number of minor ticks between every major tick
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); // The axis should begin in the origin
x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
x.title = @"x-axis";
x.titleTextStyle = textStyle;
CPTXYAxis *y = axisSet.yAxis;
y.minorTicksPerInterval = 0;
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.title = @"y-axis";
y.titleTextStyle = textStyle;
CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc]init];
dataSourceLinePlot.dataSource = self;
// Add line style
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth = 1.0f;
lineStyle.lineColor = [CPTColor greenColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
// create the fill area
dataSourceLinePlot.areaFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.2f]];
dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"0");
[graph addPlot:dataSourceLinePlot];
}
Это немного беспорядок, но я бы очень признателен за помощь.