How to add legend to Core Plot in iPhone SDK?

How can I add Legends to the core plot framework?

I am very grateful for any guidance or help.

+8
objective-c iphone cocoa-touch ios4 core-plot
source share
2 answers

There is no Legend class yet. Sometimes you can fake it using an image, but so far it is not in Core Plot. Check comment drewmcco

Legends are not yet implemented in Core Plot. You can more than contribute to their implementation within the framework.

At the same time, you can create a custom UIView with UILabels and colored lines to act as a legend for the graph, and then add it as a brother to the graph (not subordinate, or it will not display properly) and display it above the graph. Check Brad Larson's answer

+3
source share

Update: CorePlot 0.4 has the CPTLegend class:

_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 / plot / SimpleScatterPlot.m.

+26
source share

All Articles