核心数据线标签
我已经使用 Core Plot 创建了一个 CPScatterPlot,并且在图表上有几条线:
for(int i=0; i<nLines; ++i){
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.frame] autorelease];
xSquaredPlot.identifier = [NSString stringWithFormat:@"%d",i];
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.name = @"dd";
if(i==0)
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
else if (i ==1)
xSquaredPlot.dataLineStyle.lineColor = [CPColor blueColor];
else
xSquaredPlot.dataLineStyle.lineColor = [CPColor greenColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];
CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
if(i==0)
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor blueColor]];
else if (i ==1)
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
else
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor redColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
xSquaredPlot.plotSymbol = greenCirclePlotSymbol;
}
这些线显示得很好,但我似乎找不到一种方法来用标题标记每条线,或提供图例。
对此有什么想法吗?
提前致谢!
I have created a CPScatterPlot using Core Plot and have several lines on the graph:
for(int i=0; i<nLines; ++i){
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.frame] autorelease];
xSquaredPlot.identifier = [NSString stringWithFormat:@"%d",i];
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.name = @"dd";
if(i==0)
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
else if (i ==1)
xSquaredPlot.dataLineStyle.lineColor = [CPColor blueColor];
else
xSquaredPlot.dataLineStyle.lineColor = [CPColor greenColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];
CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
if(i==0)
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor blueColor]];
else if (i ==1)
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
else
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor redColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
xSquaredPlot.plotSymbol = greenCirclePlotSymbol;
}
The lines show up great, but I can't seem to find a way to label each line with it's title, or provide a legend.
Any ideas on this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:CorePlot 0.4 具有类 CPTLegend:
请参阅 CorePlot_0.4/Source/examples/CorePlotGallery/src/plots/SimpleScatterPlot.m。
Update: CorePlot 0.4 has the class CPTLegend:
See CorePlot_0.4/Source/examples/CorePlotGallery/src/plots/SimpleScatterPlot.m.
图例尚未在 Core Plot 中实现。非常欢迎您为框架贡献它们的实现。
同时,您可以构造一个带有 UILabels 和彩色线条的自定义 UIView 作为图形的图例,然后将其作为同级添加到图形中(不是子视图,否则将无法正确呈现)并将其排序为显示在图表上方。
Legends have not yet been implemented in Core Plot. You're more than welcome to contribute an implementation of them to the framework.
In the meantime, you could construct a custom UIView with UILabels and colored lines to act as the legend for the graph, then add it as a sibling to the graph (not a subview, or it will not be rendered properly) and order it to show above the graph.