0
votes

I just started using CorePlot library, and so far I'm managing to get stuff done.

I'm trying to create a piechart with some dummy data and more or less everything works as expected but for the life of me I cannot find how to style the legend items to make them look something like this:core plot legend

I can style the entire legend with background color, borders like this:

theLegend.numberOfColumns = 1;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;

as well as swatch size and row margin like this:

theLegend.swatchSize = CGSizeMake(7, 50);
theLegend.rowMargin = 5.0;

etc, but is there any way to style the individual rows of the legend backgrounds and borders?

If not, how would you suggest me to solve this?

Thank you for any help, cheers

1

1 Answers

1
votes

You can use the -attributedLegendTitleForPieChart:recordIndex: pie chart datasource method to provide the label text for each legend entry. The attributed string can represent the text color, bold text, and the different text sizes. See the "Simple Pie Chart" in the Plot Gallery example app for a demo. Insert a newline character (\n) in the string to make a second line of text.

There is currently no way to style the legend entry background separately from the background of the entire legend. Please add an enhancement request to the Core Plot issue tracker.

You could build up your own custom legend using annotations. Use a CPTBorderedLayer for the background and add layer annotations to it for each legend entry. Use a CPTBorderedLayer to draw the swatch and a CPTTextLayer to draw the text label.