3
24時間ベースのアクティビティを示すグラフを作成しようとしているログベースのアプリケーションを作成したいと考えています。 1時間は4時間(15分)に分割する必要があります。私はコアプロットを同じものに使用しようとしました。私はこれまでに行ったコードを添付して、グラフは今まで持っています。 CorePlotを使用した描画グラフでの問題
const CGFloat majorTickLength = 20; // height of the major tick
const CGFloat minorTickLength = 8.0; // height of the minor tick
// const CGFloat titleOffset = self.titleSize;
#if TARGET_OS_IPHONE
CGRect bounds = hostingView.bounds;
#else
CGRect bounds = NSRectToCGRect(hostingView.bounds);
#endif
// Create graph
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds];
[self addGraph:graph toHostingView:hostingView];
[self applyTheme:theme toGraph:graph withDefault:[CPTTheme themeNamed:kCPTSlateTheme]];
graph.fill = [CPTFill fillWithColor:[CPTColor blackColor]];
// Plot area
graph.plotAreaFrame.paddingTop = self.titleSize;
graph.plotAreaFrame.paddingBottom = self.titleSize;
graph.plotAreaFrame.paddingLeft = self.titleSize;
graph.plotAreaFrame.paddingRight = self.titleSize;
graph.plotAreaFrame.masksToBorder = NO;
// Setup plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@1440.0];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@20.0];
// Line styles
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0;
CPTMutableLineStyle *majorTickLineStyle = [axisLineStyle mutableCopy];
majorTickLineStyle.lineWidth = 1.0;
majorTickLineStyle.lineCap = kCGLineCapRound;
CPTMutableLineStyle *minorTickLineStyle = [axisLineStyle mutableCopy];
minorTickLineStyle.lineWidth = 1.0;
minorTickLineStyle.lineCap = kCGLineCapButt;
// Text styles
CPTMutableTextStyle *axisTitleTextStyle = [CPTMutableTextStyle textStyle];
axisTitleTextStyle.fontName = @"Helvetica-Bold";
CPTMutableNumberSet *majorTickLocations = [NSMutableSet set];
for (int i = 60; i <= 1440; i += 60)
{
[majorTickLocations addObject:@(i)];
}
CPTMutableNumberSet *minorTickLocations = [NSMutableSet set];
for (NSUInteger loc = 0; loc <= 1440; loc += 15)
{
[minorTickLocations addObject:@(loc)];
}
// Axis1
CPTXYAxis *axis1 = [[CPTXYAxis alloc] init];
axis1.plotSpace = graph.defaultPlotSpace;
axis1.labelingPolicy = CPTAxisLabelingPolicyNone;
axis1.orthogonalPosition = @1.0;
axis1.tickDirection = CPTSignPositive;
axis1.axisLineStyle = axisLineStyle;
axis1.majorTickLength = majorTickLength;
axis1.majorTickLineStyle = majorTickLineStyle;
axis1.minorTickLength = minorTickLength;
axis1.minorTickLineStyle = minorTickLineStyle;
axis1.majorTickLocations = majorTickLocations;
axis1.minorTickLocations = minorTickLocations;
// Axis2
CPTXYAxis *axis2 = [[CPTXYAxis alloc] init];
axis2.plotSpace = graph.defaultPlotSpace;
axis2.labelingPolicy = CPTAxisLabelingPolicyNone;
axis2.orthogonalPosition = @2.0;
axis2.tickDirection = CPTSignPositive;
axis2.axisLineStyle = axisLineStyle;
axis2.majorTickLength = majorTickLength;
axis2.majorTickLineStyle = majorTickLineStyle;
axis2.minorTickLength = minorTickLength;
axis2.minorTickLineStyle = minorTickLineStyle;
axis2.majorTickLocations = majorTickLocations;
axis2.minorTickLocations = minorTickLocations;
// Axis3
CPTXYAxis *axis3 = [[CPTXYAxis alloc] init];
axis3.plotSpace = graph.defaultPlotSpace;
axis3.labelingPolicy = CPTAxisLabelingPolicyNone;
axis3.orthogonalPosition = @3.0;
axis3.tickDirection = CPTSignPositive;
axis3.axisLineStyle = axisLineStyle;
axis3.majorTickLength = majorTickLength;
axis3.majorTickLineStyle = majorTickLineStyle;
axis3.minorTickLength = minorTickLength;
axis3.minorTickLineStyle = minorTickLineStyle;
axis3.majorTickLocations = majorTickLocations;
axis3.minorTickLocations = minorTickLocations;
// Axis4
CPTXYAxis *axis4 = [[CPTXYAxis alloc] init];
axis4.plotSpace = graph.defaultPlotSpace;
axis4.labelingPolicy = CPTAxisLabelingPolicyNone;
axis4.orthogonalPosition = @4.0;
axis4.tickDirection = CPTSignPositive;
axis4.axisLineStyle = axisLineStyle;
axis4.majorTickLength = majorTickLength;
axis4.majorTickLineStyle = majorTickLineStyle;
axis4.minorTickLength = minorTickLength;
axis4.minorTickLineStyle = minorTickLineStyle;
axis4.majorTickLocations = majorTickLocations;
axis4.minorTickLocations = minorTickLocations;
CPTMutableAxisLabelSet *axis4LabelSet = [NSMutableSet set];
for (NSUInteger i = 1; i < 24; i++)
{
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%lu", (unsigned long)i]
textStyle:axis4.labelTextStyle];
newLabel.tickLocation = @(i*60);
newLabel.offset = axis4.labelOffset + axis4.majorTickLength;
[axis4LabelSet addObject:newLabel];
}
axis4.axisLabels = axis4LabelSet;
// Add axes to the graph
graph.axisSet.axes = @[axis1, axis2, axis3, axis4];
は、私の上記のコードでは、私は15分の間隔を表すために毎時間とminorTickLocationsを表すためにmajorTickLocationsを使用することができました。しかし、私の望む出力は次のようなイメージです。それぞれの30分のマークは異なるようにも表示する必要があります。どのように私はこれを達成することができます。
majorGridLinesをいくつかのサンプルコードplで設定する方法についていくつかの光を見せてくれますか? – Mano
majorGridLinesの位置を指定する方法 – Mano
つまり、プロパティaxis5.majorGridLinesの値を指定する方法は? – Mano