How Add a legend to Core Plot in iPhone SDK?
Asked Answered
T

2

8

How can I add Legends in Core Plot framework?

I am greatly appreciative of any guidance or help.

Tartarus answered 21/4, 2011 at 7:13 Comment(0)
O
3

There is no Legend class yet. You can fake it using an image sometimes, but it is not in Core Plot yet. Check drewmcco Comment

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. Check Brad Larson Answer

Olva answered 21/4, 2011 at 8:26 Comment(5)
will you please explain me more about how to Add view as sibling to coreplot graphTartarus
Can't you add an image as a subview of the graph view?Olva
Thanks for reply, Actualy I am newer to coreplot and I am still not much clear with the flow of coreplot.so will you guide me moreTartarus
@Prerak: I have not gone to much in coreplot, but i suggest some stuff; CPXYGraph* graph = [[CPXYGraph alloc] initWithFrame: frame]; can't you say [graph addSubView:Image];Olva
Instead of adding a sublayer to the Core Plot graph, you could add a CPAnnotation to your graph. Depending on the type of annotation you want, you can anchor it to view (~screen) coordinates or plot coordinates. An annotation uses a CPLayer, which is a subclass of CALayer, to actually display the annotation. You can create a CPLayer and add your image as the layer "contents".Metzger
H
26

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.

Hereditable answered 8/8, 2011 at 18:17 Comment(0)
O
3

There is no Legend class yet. You can fake it using an image sometimes, but it is not in Core Plot yet. Check drewmcco Comment

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. Check Brad Larson Answer

Olva answered 21/4, 2011 at 8:26 Comment(5)
will you please explain me more about how to Add view as sibling to coreplot graphTartarus
Can't you add an image as a subview of the graph view?Olva
Thanks for reply, Actualy I am newer to coreplot and I am still not much clear with the flow of coreplot.so will you guide me moreTartarus
@Prerak: I have not gone to much in coreplot, but i suggest some stuff; CPXYGraph* graph = [[CPXYGraph alloc] initWithFrame: frame]; can't you say [graph addSubView:Image];Olva
Instead of adding a sublayer to the Core Plot graph, you could add a CPAnnotation to your graph. Depending on the type of annotation you want, you can anchor it to view (~screen) coordinates or plot coordinates. An annotation uses a CPLayer, which is a subclass of CALayer, to actually display the annotation. You can create a CPLayer and add your image as the layer "contents".Metzger

© 2022 - 2024 — McMap. All rights reserved.