核心数据线标签 [英] core data line labels
本文介绍了核心数据线标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用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 =自我;
[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;
}
行显示很好,但我似乎找不到办法
对此有任何想法吗?
谢谢
解决方案
更新:CorePlot 0.4的类为CPTLegend:
_graph.legend = [CPTLegend legendWithGraph:_graph];
_graph.legend.textStyle = x.titleTextStyle;
_graph.legend.fill = [CPTFill fillWithColor:[CPTColor darkGrayColor]];
_graph.legend.borderLineStyle = x.axisLineStyle;
_graph.legend.cornerRadius = 5.0;
_graph.legend.swatchSize = CGSizeMake(25.0,25.0);
_graph.legendAnchor = CPTRectAnchorBottom;
_graph.legendDisplacement = CGPointMake(0.0,12.0);
请参阅CorePlot_0.4 / Source / examples / CorePlotGallery / src / plots / SimpleScatterPlot.m。
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!
解决方案
Update: CorePlot 0.4 has the class CPTLegend:
_graph.legend = [CPTLegend legendWithGraph:_graph];
_graph.legend.textStyle = x.titleTextStyle;
_graph.legend.fill = [CPTFill fillWithColor:[CPTColor darkGrayColor]];
_graph.legend.borderLineStyle = x.axisLineStyle;
_graph.legend.cornerRadius = 5.0;
_graph.legend.swatchSize = CGSizeMake(25.0, 25.0);
_graph.legendAnchor = CPTRectAnchorBottom;
_graph.legendDisplacement = CGPointMake(0.0, 12.0);
See CorePlot_0.4/Source/examples/CorePlotGallery/src/plots/SimpleScatterPlot.m.
这篇关于核心数据线标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文