I am trying to place a legend outside a Piechart without success. When I create the legend modifier like below everything works as expected:
let legendModifier = SCIPieChartLegendModifier()
legendModifier.sourceSeries = renderableSeries
legendModifier.margins = UIEdgeInsets(top: 17, left: 17, bottom: 17, right: 17)
legendModifier.position = [.bottom, .centerHorizontal]
However when I try to place it outside like below the app crashes with:
NSInvalidArgumentException’, reason: ‘-[SCIPieSegment seriesName]: unrecognized selector sent to instance 0x281881500
legend = SCIChartLegend()
legend.backgroundColor = SCIColor(.red)
let dataSource = SCISeriesInfoLegendDataSource(legend: legend)
legendModifier = SCIPieChartLegendModifier(legend: legend, dataSource: dataSource, useAutoPlacement: false)
legendModifier.sourceSeries = renderableSeries.series
legendModifier.margins = UIEdgeInsets(top: 17, left: 17, bottom: 17, right: 17)
legendModifier.position = [.left, .top]
Note: I am using SwiftIUI and add the legend container to the swiftui view wrapped in an UIViewRepresentable
UIViewRepresentable(container: legend.container!)
if i comment out legendModifier.sourceSeries = renderableSeries.series the crash does not appear but the legend does not show.
- Marcus Maringer asked 2 years ago
- last edited 2 years ago
-
I am afraid I was not clear enough in my question. I not only wanted to place the legend outside but also be able to customize its look. like with a different background color. this is why i need access to the legend.
-
Thanks marcus for additional information, will circle back to the team. In the meantime, have a look at the LegendModifier docs. There is a part on placement outside chart. https://www.scichart.com/documentation/ios/current/legend-modifier.html
- You must login to post comments
Good morning Marcus
So the legend can be placed in a Pie Chart like this. Try this code in your app:
let legendModifier = SCIPieChartLegendModifier()
legendModifier.sourceSeries = pieSeries;
legendModifier.margins = SCIEdgeInsets(top: 17, left: 17, bottom: 17, right: 17)
legendModifier.position = [.bottom, .centerHorizontal];
This results in the following output:
Try that, does it meet your requirements?
Best regards
Andrew
- Andrew Burnett-Thompson answered 2 years ago
- You must login to post comments
Please login first to submit.