core data line labels
Asked Answered
R

2

1

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!

Remindful answered 9/3, 2010 at 17:33 Comment(1)
bute here is some prob of setting fram/position of the legend. How sh'd i set the fram as i needed. (completely at the bottom of the view)Lillith
C
4

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.

Conditioned answered 8/8, 2011 at 18:24 Comment(1)
yes thank for providing valuable info. bute here is some prob of setting fram/position of the legend. How sh'd i set the fram as i needed. (completely at the bottom of the view)Lillith
S
0

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.

Slightly answered 9/3, 2010 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.