1

我有一个使用 core plot 1.0 工作的条形图,当我升级到更新版本的 Core Plot 时,我现在在图表的左侧(y 轴)得到黑色的喜欢。

在此处输入图像描述

我对核心情节很陌生,不知道为什么现在会发生这种情况。

-(void)configureHost {
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
self.hostView.allowPinchScaling = YES;
[self.view addSubview:self.hostView];

-(void)configureGraph {
// 1 - Create the graph
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
graph.plotAreaFrame.masksToBorder = NO;
self.hostView.hostedGraph = graph;
// 2 - Configure the graph
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
graph.paddingBottom = 30.0f;
graph.paddingLeft  = 30.0f;
graph.paddingTop    = -1.0f;
graph.paddingRight  = -5.0f;
// 3 - Set up styles
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor blackColor];
titleStyle.fontName = @"Helvetica-Bold";
titleStyle.fontSize = 16.0f;
// 4 - Set up title
NSString *title = @"Mar 2012 - Apr 2013";
graph.title = title;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -16.0f);
// 5 - Set up plot space
CGFloat xMin = 0.0f;
CGFloat xMax = 12.0f;
CGFloat yMin = 0.0f;
CGFloat yMax = 1000.0;  // should determine dynamically based on max price
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xMin) length:CPTDecimalFromFloat(xMax)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(yMax)];

-(void)configurePlots {
self.myUsagePlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:1/255.0f green:167/255.0f blue:210/255.0f alpha:1.0f] horizontalBars:NO];
self.myUsagePlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:1/255.0f green:167/255.0f blue:210/255.0f alpha:1.0f]];
self.myUsagePlot.identifier = PGEHomeSymbolMy;
CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineColor = [CPTColor lightGrayColor];
barLineStyle.lineWidth = 0.5;

CPTGraph *graph = self.hostView.hostedGraph;
CGFloat barX = PGEBarInitialX;
NSArray *plots = [NSArray arrayWithObjects:self.myUsagePlot, nil];

for (CPTBarPlot *plot in plots) {
    plot.dataSource = self;
    plot.delegate = self;
    plot.barWidth = CPTDecimalFromDouble(PGEBarWidth);
    plot.barOffset = CPTDecimalFromDouble(barX);
    plot.lineStyle = barLineStyle;
    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
    barX +=PGEBarWidth;
}

-(void)configureAxes {

// 1 - Configure styles
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor blackColor];
axisTitleStyle.fontName = @"Helvetica-Bold";
axisTitleStyle.fontSize = 14.0f;
CPTMutableLineStyle *axisLineStyle = [CPTLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0;
axisLineStyle.lineColor = [[CPTColor blackColor] colorWithAlphaComponent:1];
// 2 - Get the graph's axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
// 3 - Configure the x-axis
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axisSet.xAxis.title = @"Months";
axisSet.xAxis.titleTextStyle = axisTitleStyle;
axisSet.xAxis.titleOffset = 10.0f;
axisSet.xAxis.axisLineStyle = axisLineStyle;
// 4 - Configure the y-axis
axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axisSet.yAxis.title = @"Usage";
axisSet.yAxis.titleTextStyle = axisTitleStyle;
axisSet.yAxis.titleOffset = 5.0f;
axisSet.yAxis.axisLineStyle = axisLineStyle;
4

1 回答 1

1

这是 Core Plot 1.2 的一个已知问题。使用 Mercurial 提取最新代码以获取修复,或在设置标签策略后设置axisLabelsminorTickAxisLabelsmajorTickLocations和/或。minorTickLocationsnil

于 2013-05-04T01:25:26.947 回答