0

相互にプロットするグラフがいくつかあり、時間の x 軸を共有する必要がありますが、y 軸は異なります...これを行うには、2 番目から 2 番目までの新しいプロット スペースを作成する必要があることを知っています。 n 番目のグラフを作成し、それらのプロット スペースをグラフに追加します。

これが私の「ダイアグラムに新しいグラフを追加する」機能のスニペットです

BOOL isNew=FALSE;
CPTXYPlotSpace *defaultPlotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
CPTXYPlotSpace *plotSpace=nil;
if([g_Data count]==1){
    plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    NSLog(@"Reuse existing plot space");
}
else
{
    NSLog(@"New plot space");
    plotSpace = [[CPTXYPlotSpace alloc] init];
    isNew=TRUE;
}

[dataDictionary setObject:plotSpace forKey:@"plotspace"];



float xSize=[mainGraphView bounds].size.width;
float ySize=[mainGraphView bounds].size.height;

float XRatio=(xSize-50.0)/xSize;
float YRatio=(ySize-50.0)/ySize;

NSDecimalNumber *plotWidth=[x_max decimalNumberBySubtracting:x_min];
plotWidth=[plotWidth decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%0.2f",XRatio]]];
NSDecimalNumber *plotX=[x_min decimalNumberBySubtracting:[plotWidth decimalNumberBySubtracting:[x_max decimalNumberBySubtracting:x_min]]];

NSDecimalNumber *plotHeight=[y_max decimalNumberBySubtracting:y_min];
plotHeight=[plotHeight decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%0.2f",YRatio]]];
NSDecimalNumber *plotY=[y_min decimalNumberBySubtracting:[plotHeight decimalNumberBySubtracting:[y_max decimalNumberBySubtracting:y_min]]];




NSLog(@"%@: XRange: Original: %@ x %0.2f becomes %@",identifier,[x_max decimalNumberBySubtracting:x_min],XRatio,plotWidth);
NSLog(@"%@: YRange: %@-%@ is %@ x %0.2f becomes %@",identifier,y_min,y_max,[y_max decimalNumberBySubtracting:y_min],YRatio,plotHeight);

if(isNew){
    plotSpace.xRange = defaultPlotSpace.xRange;
}
else
{
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:[plotX decimalValue] length:[plotWidth decimalValue]];
}
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:[plotY decimalValue]
                                                length:[plotHeight decimalValue]];
NSLog(@"**********YPLOT IS FROM %@ len %@",plotY,plotHeight );



plotSpace.allowsUserInteraction=TRUE;
if(isNew)[graph addPlotSpace:plotSpace];



CPTScatterPlot *newPlot = [[CPTScatterPlot alloc] initWithFrame:graph.bounds];
newPlot.identifier     = identifier;
newPlot.dataSource =       self;



CPTMutableLineStyle *lineStyle = [newPlot.dataLineStyle mutableCopy];
lineStyle.lineWidth              = 2.0;
lineStyle.lineColor              = graphColor;
newPlot.dataLineStyle = lineStyle;
[g_Plots addObject:newPlot];

[graph addPlot:newPlot toPlotSpace:plotSpace];



NSLog(@"Adding plot to graph system");
[graph addPlot:newPlot];




and my log:



     2013-10-28 15:24:35.166 BodyMetrics[2234:303] -------[NEW PLOT FOR Pulse (bpm)]-----------------------------------------------------------
    2013-10-28 15:24:35.169 BodyMetrics[2234:303] 85 rows for data: BM_Measure measuredate measuretype = 'Heart Pulse'
    2013-10-28 15:24:35.173 BodyMetrics[2234:303] The size of the arrays for x and y are: 85;85
    2013-10-28 15:24:35.173 BodyMetrics[2234:303] XMIN: 1380566085  XMAX: 1382980783
    2013-10-28 15:24:35.173 BodyMetrics[2234:303] YMIN: 43  YMAX: 154
    2013-10-28 15:24:35.173 BodyMetrics[2234:303] Reuse existing plot space
    2013-10-28 15:24:35.174 BodyMetrics[2234:303] Pulse (bpm): XRange: Original: 2414698 x 0.95 becomes 2541787.36842105263157894736842105263157
    2013-10-28 15:24:35.174 BodyMetrics[2234:303] Pulse (bpm): YRange: 43-154 is 111 x 0.90 becomes 123.333333333333333333333333333333333333
    2013-10-28 15:24:35.174 BodyMetrics[2234:303] **********YPLOT IS FROM 30.666666666666666666666666666666666667 len 123.333333333333333333333333333333333333
    2013-10-28 15:24:35.175 BodyMetrics[2234:303] Adding plot to graph system
    2013-10-28 15:24:35.176 BodyMetrics[2234:303] Added... 1
    2013-10-28 15:24:35.176 BodyMetrics[2234:303] Configure axes
    2013-10-28 15:24:35.177 BodyMetrics[2234:303] Now addign Y axes...
    2013-10-28 15:24:35.177 BodyMetrics[2234:303] Creating axis for Pulse (bpm)
    2013-10-28 15:24:35.177 BodyMetrics[2234:303] Reusing the existing Y Axis...
    2013-10-28 15:24:35.178 BodyMetrics[2234:303] This axes is from 43 to 154 being a range of 111 so the major ticks will bat 10.3 floats away, for an interval length of 10.7766990291262135922330097087378640776
    2013-10-28 15:24:35.178 BodyMetrics[2234:303] About to add the following axes: 2 (
        "<<<CPTXYAxis: 0x10040ca80> bounds: {{0, 0}, {959, 515}}> with range: <<CPTPlotRange: 0x60800027cc40> {1380438995.6315789473684210526315789474, 2541787.36842105263157894736842105263157}> viewCoordinates: {0, 50} to {959, 50}>",
        "<<<CPTXYAxis: 0x10040d8f0> bounds: {{0, 0}, {959, 515}}> with range: <<CPTPlotRange: 0x60800027cd00> {30.666666666666666666666666666666666667, 123.333333333333333333333333333333333333}> viewCoordinates: {50, 0} to {50, 515}>"
    ) 
    2013-10-28 15:24:35.179 BodyMetrics[2234:303] Added
    2013-10-28 15:24:35.179 BodyMetrics[2234:303] -------[NEW PLOT FOR Weight (Kg)]-----------------------------------------------------------
    2013-10-28 15:24:35.181 BodyMetrics[2234:303] 44 rows for data: BM_Measure measuredate measuretype = 'Weight'
    2013-10-28 15:24:35.183 BodyMetrics[2234:303] The size of the arrays for x and y are: 44;44
    2013-10-28 15:24:35.183 BodyMetrics[2234:303] XMIN: 1380330622  XMAX: 1382957809
    2013-10-28 15:24:35.183 BodyMetrics[2234:303] YMIN: 83.225  YMAX: 85.701
    2013-10-28 15:24:35.183 BodyMetrics[2234:303] New plot space
    2013-10-28 15:24:35.183 BodyMetrics[2234:303] Weight (Kg): XRange: Original: 2627187 x 0.95 becomes 2765460
    2013-10-28 15:24:35.184 BodyMetrics[2234:303] Weight (Kg): YRange: 83.225-85.701 is 2.476 x 0.90 becomes 2.75111111111111111111111111111111111111
    2013-10-28 15:24:35.184 BodyMetrics[2234:303] **********YPLOT IS FROM 82.9498888888888888888888888888889 len 2.75111111111111111111111111111111111111
    2013-10-28 15:24:35.184 BodyMetrics[2234:303] Adding plot to graph system
    2013-10-28 15:24:35.184 BodyMetrics[2234:303] Added... 2
    2013-10-28 15:24:35.185 BodyMetrics[2234:303] Configure axes
    2013-10-28 15:24:35.185 BodyMetrics[2234:303] Now addign Y axes...
    2013-10-28 15:24:35.185 BodyMetrics[2234:303] Creating axis for Pulse (bpm)
    2013-10-28 15:24:35.185 BodyMetrics[2234:303] Reusing the existing Y Axis...
    2013-10-28 15:24:35.185 BodyMetrics[2234:303] This axes is from 43 to 154 being a range of 111 so the major ticks will bat 10.3 floats away, for an interval length of 10.7766990291262135922330097087378640776
    2013-10-28 15:24:35.186 BodyMetrics[2234:303] Creating axis for Weight (Kg)
    2013-10-28 15:24:35.186 BodyMetrics[2234:303] Adding a new Y axis...
    2013-10-28 15:24:35.186 BodyMetrics[2234:303] This axes is from 83.225 to 85.701 being a range of 2.476 so the major ticks will bat 10.3 floats away, for an interval length of 0.240388349514563106796116504854368932038
    2013-10-28 15:24:35.187 BodyMetrics[2234:303] About to add the following axes: 2 (
        "<<<CPTXYAxis: 0x10040ca80> bounds: {{0, 0}, {959, 515}}> with range: <<CPTPlotRange: 0x60800027cc40> {1380438995.6315789473684210526315789474, 2541787.36842105263157894736842105263157}> viewCoordinates: {0, 50} to {959, 50}>",
        "<<<CPTXYAxis: 0x10040d8f0> bounds: {{0, 0}, {959, 515}}> with range: <<CPTPlotRange: 0x60800027cd00> {30.666666666666666666666666666666666667, 123.333333333333333333333333333333333333}> viewCoordinates: {50, 0} to {50, 515}>"
    ) 
    2013-10-28 15:24:35.187 BodyMetrics[2234:303] Added

ただし、グラフが正しくスケーリングされません。

ここに画像の説明を入力

4

1 に答える 1

1

プロットをグラフに 2 回追加しています。最初は で[graph addPlot:newPlot toPlotSpace:plotSpace];、もう一度 で追加し[graph addPlot:newPlot];ます。2 番目の呼び出しは、最初のプロット用に構成されたデフォルトのプロット スペースにプロットを戻します。

への冗長な呼び出しを削除します-addPlot:

于 2013-10-30T00:20:25.997 に答える