核心数据线标签

发布于 2024-08-25 00:50:47 字数 1172 浏览 3 评论 0原文

我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

带上头具痛哭 2024-09-01 00:50:47

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

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.

南薇 2024-09-01 00:50:47

图例尚未在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文