0
我正在嘗試繪製使用core-plot的折線圖,並且遇到了x軸標籤的問題。 這裏是我的代碼:自定義標籤不會顯示[core-plot]
graph = [[CPTXYGraph alloc] initWithFrame:self._graphView.bounds];
CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
[graph applyTheme:theme];
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self._graphView;
[hostingView setHostedGraph:graph];
[self.view addSubview:hostingView];
graph.paddingLeft = 10.0;
graph.paddingTop = 10.0;
graph.paddingRight = 10.0;
graph.paddingBottom = 10.0;
graph.plotAreaFrame.paddingLeft = 55.0;
graph.plotAreaFrame.paddingTop = 50.0;
graph.plotAreaFrame.paddingRight = 20.0;
graph.plotAreaFrame.paddingBottom = 90.0;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt([examValues count])];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromDouble([self getYRange] + 10)];
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;
CPTXYAxisSet *axisSet = (id)graph.axisSet;
axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyEqualDivisions;
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[examValues count]];
static CPTMutableTextStyle *labelTextStyle = nil;
labelTextStyle = [[CPTMutableTextStyle alloc] init];
labelTextStyle.color = [CPTColor blackColor];
labelTextStyle.fontSize = 10.0f;
int index = 1;
for (SmartAssetInspectionResultHistoryDTO *result in examValues) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:result._inspectiondate textStyle:labelTextStyle];
newLabel.tickLocation = CPTDecimalFromInt(index);
newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength;
newLabel.rotation = M_PI/4;
[customLabels addObject:newLabel];
[newLabel release];
index ++;
}
axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels];
axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(@"20");
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromInt(0);
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.labelOffset = 3.0f;
CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease];
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
plot.identifier = @"Date Plot";
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
plot.dataLineStyle = dataLineStyle;
plot.dataSource = self;
CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(5.0, 5.0);
plot.plotSymbol = greenCirclePlotSymbol;
[graph addPlot:plot];
一些評論:
examValues <--- A NSMutableArray storing some data .
SmartAssetInspectionResultHistoryDTO <--- Detail info object stored in examValues .
result._inspectiondate <--- Date info I want to display in the x axis' labels .
我的麻煩:沒有日期顯示下方X軸,但浮動值,像 '1.0', '2.0' ... 誰可以告訴我問題在哪裏?
這工作。謝謝 。 – Sabbath 2012-07-26 08:20:55