同じ散布図を使用して、表示するデータの種類に応じて 5 行または 4 行を表示しています。散布図に線を配置するコードは次のとおりです。
if (typeSelector.selectedSegmentIndex == 0) {
if ([plot.identifier isEqual:@"Hotel"]) { nums = valuesQT1; }
if ([plot.identifier isEqual:@"Retail"]) { nums = valuesQT2; }
if ([plot.identifier isEqual:@"Office"]) { nums = valuesQT3; }
if ([plot.identifier isEqual:@"Industrial"]) { nums = valuesQT4; }
if ([plot.identifier isEqual:@"Apartment"]) { nums = valuesQT5; }
}
else {
if ([plot.identifier isEqual:@"East"]) { nums = valuesQR1; }
if ([plot.identifier isEqual:@"South"]) { nums = valuesQR2; }
if ([plot.identifier isEqual:@"Midwest"]) { nums = valuesQR3; }
if ([plot.identifier isEqual:@"West"]) { nums = valuesQR4; }
}
したがって、凡例は、typeSelector が 0 の場合、ホテル、小売、オフィス、産業、およびアパートのスウォッチとラベルを表示し、typeSelector が 1 の場合、East、South、Midwest、および West のスウォッチとラベルを表示する必要があります。
すべての散布図は同じ折れ線グラフを使用します。
lineChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
linePlotView.hostedGraph = lineChart;
各データ セットは、以下を使用して lineChart に追加されます。
[lineChart addPlot:amtPlot1];
[lineChart addPlot:amtPlot2];
[lineChart addPlot:amtPlot3];
など。
ラベルコードは次のとおりです。
// Add legend
if (typeSelector.selectedSegmentIndex == 0) {
CPTLegend *theLegend = [CPTLegend legendWithGraph:lineChart];
theLegend.swatchSize = CGSizeMake(30.0, 20.0);
CPTMutableTextStyle *blackTextStyle = [CPTMutableTextStyle textStyle];
blackTextStyle.color = [CPTColor blackColor];
blackTextStyle.fontSize = 12.0;
theLegend.numberOfRows = 5;
lineChart.legend = theLegend;
lineChart.legend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
lineChart.legendAnchor = CPTRectAnchorLeft;
lineChart.legendDisplacement = CGPointMake(100.0, 0.0);
}
これは、散布図の最初の 5 行のセットで完全に機能します。ただし、4 行の 2 番目のセットで同様のコードを使用すると、最初のセットの凡例スウォッチとラベルが 2 番目のセットと共に表示されます。
最初のセットには 5 つのスウォッチとラベルを含む凡例が必要で、2 番目のセットには 4 つのスウォッチとラベルを含む凡例が必要です。
これは、lineChart1 (最初の 5 の場合) と lineChart2 (2 番目の 4 の場合) のような 2 つの別個のグラフを作成する必要なしに可能ですか?