核心数据线标签

时间:2010-03-09 17:33:49

标签: iphone core-plot

我使用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;
 }

线条显示效果很好,但我似乎找不到用标题标记每一行的方法,或者提供一个图例。

有关于此的任何想法吗?

提前致谢!

2 个答案:

答案 0 :(得分:4)

更新: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。

答案 1 :(得分:0)

Core Plot中尚未实现传奇。非常欢迎您将这些实现贡献给框架。

与此同时,您可以使用UILabels和彩色线构建自定义UIView作为图形的图例,然后将其添加为图形的兄弟(不是子视图,或者它将无法正确呈现)和命令它显示在图表上方。