我添加了两个带有barOffset的条形图,以便两个条形图并排显示。
我还想使用相同的数据添加两个散点图,每个散点图分别接触每个条形图的尖端。
下面是我如何添加两个散点图的方法。
//Add line graph 1
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = @"Scatter-Plot-1";
CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.miterLimit = 1.0f;
lineStyle.lineWidth = 3.0f;
lineStyle.lineColor = [CPTColor orangeColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot toPlotSpace:barPlotSpace];
//Add line graph 2
CPTScatterPlot *dataSourceLinePlot2 = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot2.identifier = @"Scatter-Plot-2";
CPTMutableLineStyle *lineStyle2 = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle2.miterLimit = 1.0f;
lineStyle2.lineWidth = 3.0f;
lineStyle2.lineColor = [CPTColor greenColor];
dataSourceLinePlot2.dataLineStyle = lineStyle2;
dataSourceLinePlot2.dataSource = self;
[graph addPlot:dataSourceLinePlot2 toPlotSpace:barPlotSpace];但现在,当数据值相同时,两个散点图都从第一个条形图尖端开始
我要他们每个人都只接触条形图的尖端。
我该怎么做呢?有没有什么barOffset之类的东西可以让scatter移动它?
我正确地实现了委托,数据也正确地显示出来。
发布于 2012-02-14 11:42:40
如果barWidthsAreInViewCoordinates为NO (默认值),则只需在数据源的x或y坐标中添加或减去barOffset即可。
发布于 2018-04-27 04:41:39
您也可以调整plotSpace的偏移,例如,从0.4 - barPlotSpace.xRange =CPTPlotRange(位置:0.5,长度: can (值:结束))开始,但在这种情况下,整个绘图将发生偏移。
或者像上面建议的那样更好:在数据源'number‘中
public func number(for plot: CPTPlot, field: UInt, record: UInt) -> Any?
{
let idt = plot.identifier as! NSString;
switch CPTBarPlotField(rawValue: Int(field))! {
case .barLocation:
if idt.compare("Scatter-Plot-1") == .orderedSame {
// This will shift the Scatter-Plot-1 to the left
return NSNumber(value: Double(record) + 0.5)
} else {
return record as NSNumber
}
case .barTip:
//Enter your code
return nil
default:
return nil
}
}https://stackoverflow.com/questions/9262301
复制相似问题