我有一个obj-c iOS应用程序,它使用CorePlot打印计算角度的图表。角度域的x轴和时间的y轴。图表在从上到下滚动的时间内发生变化以显示度数。 y轴以这些角度阵列的平均值为中心。数据源是NSMutableArray,a包含度。
外部模块每秒分析原始数据,以生成新的计算角度,以便在图表中显示。图表更新非常秒,y轴向下滚动显示时间流(类似于CorePlot演示项目,带有用于连续滚动数据的计时器,但垂直不是水平的)。
有时此操作无法生成(角度与计算的最后一个角度相同)一个新角度,但我仍然需要更新图表以显示时间流。问题是:
1)我可以在orde中更改这些点的颜色,以突出显示这段时间内的缺失数据吗?
2)我可以突出显示此区域以显示数据不存在的位置吗?像这样的东西(但垂直的风格) https://keystrokecountdown.com/articles/corePlot/index.html
这是我目前的实施:
1)配置绘图区域(某些图形设置)
- (void)initPlot {
[self configureHost];
[self configureGraph];
[self configurePlots];
[self configureAxes];
}
2)数据来源。从数据源(数组)中选择数据以在图表中显示。 x =数组值,y =数组索引
#pragma mark - Core Plot Data Source
- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
if ([((NSString *)plot.identifier) isEqualToString:@"MY_ID"]) {
return [degreesArray count];
}
}
- (NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
NSNumber *num;
if ([((NSString *)plot.identifier) isEqualToString:@"MY_ID"]) {
if (fieldEnum == CPTScatterPlotFieldX) {
num = [degreesArray objectAtIndex:index];
} else {
num = [NSNumber numberWithInt:(int)index + currentIndex - (int)degreesArray.count];
}
}
return num;
}
3)用新角度更新图表
- (void)newSetData:(int)newData {
// Check the correct plot
CPTGraph *leftGraph = self.leftPlot.hostedGraph;
CPTPlot *leftPlot = [leftGraph plotWithIdentifier:@"MY_ID"];
if (leftPlot) {
if (degreesArray.count > kDataOnGraph) {
NSRange range;
range.location = 0;
range.length = degreesArray.count-kDataOnGraph;
[degreesArray removeObjectsInRange:range];
[leftPlot deleteDataInIndexRange:range];
}
// Updating y axis range
[self updateSetYAxis];
currentIndex++;
newAngle = ...;
// Saving new SET data
[degreesArray addObject:[NSNumber numberWithInt:(int)newAngle]];
lastAngle_ = [NSNumber numberWithInt:newAngle];
// Adding new SET data to chart
[leftPlot insertDataAtIndex:degreesArray.count - 1 numberOfRecords:1];
// Updating axis
[self updateSetXAxis];
[self updateSetLabels];
}
}
答案 0 :(得分:0)
在<CPTScatterPlotDataSource>
中,实施-symbolForScatterPlot:recordIndex:
方法为每个数据点提供符号。对于具有新数据的点使用一个,对于没有的点使用另一个。如果对具有相同外观的点重复使用符号对象,而不是为每个绘图点创建新符号,则会获得更好的绘图性能。
在y轴上使用背景限制带来突出显示缺失的数据范围。