Search code examples
objective-ccocoacore-plotcocoa-bindings

How to configure Core Plot Data Labels with Bindings


I'm attempting to set up a pie chart using core plot and bindings. I can get the chart to display properly using CPTPieChartBindingPieSliceWidthValues

[pieChart bind:CPTPieChartBindingPieSliceWidthValues
    toObject:[self sectorAllocation]
       withKeyPath:@"arrangedObjects.sectorPercentage"
           options:nil];

(sectorAllocation is a NSArray Controller)

Similarly I tried bind data labels using CPTPlotBindingDataLabels

[pieChart bind:CPTPlotBindingDataLabels
          toObject:[self sectorAllocation]
       withKeyPath:@"arrangedObjects.sectorName"
           options:nil];

(sectorName is a NSString value)

However this doesn't seem to work i receive the following error in the console

[__NSCFString setShadow:]: unrecognized selector sent to instance 0x60800023fb00

It seems it doesn't like a string object, so how would i go about this? and what type of object is it looking for?


Solution

  • The binding expects an NSArray of Core Plot layers (CPTLayer), one for each data index. CPTTextLayer is a common choice since it displays text, but other layer types are allowed, too.