Swift: Shinobi Chart Donut Legend Title


I’m try to make a simpe Shinobi Chart Donut with Swift. But i have a liitle problems like :

  1. How to show that label if slice clicked? I try this func but its not working to show a simple text

    func sChart(_ chart: ShinobiChart, labelForSliceAt sliceIndex: Int, in series: SChartRadialSeries) -> UILabel {
    var label: UILabel = UILabel()

     label.text = "dffd"
     return label


  2. How to change background color behind the chart (white background) ?

I try this but not working too :

        chart?.layer.backgroundColor = UIColor.clear.cgColor

I have read some article regarding my problem but there are little was writing with Swift. Any suggest and answer will help. Thanks in Advance


Hi MrX,

The function you provided sets the label for a slice whether or not it’s selected. (Make sure you’ve set the chart’s delegate correctly so this function is called.)

If you want something to change when a slice is selected, you should take a look at the method sChart(_ chart: ShinobiChart, toggledSelectionFor dataPoint: SChartRadialDataPoint, in series: SChartRadialSeries, at pixelPoint: CGPoint).

The pie chart in the shinobicharts Samples app (which is written in Swift) uses this method, so it may help to take a look at that.

You can change the chart’s background color using:

chart.backgroundColor = .clear

You may also need to change the plot area’s background color as follows:

chart.plotAreaBackgroundColor = .clear




I solved with this func :

func sChart(_ chart: ShinobiChart, labelForSliceAt sliceIndex: Int, in series: SChartRadialSeries) -> UILabel {
    let sliceLabel = UILabel(frame: CGRect(x: 0, y: 10, width: 200, height: 11))
    sliceLabel.numberOfLines = 0
    switch sliceIndex {
    case 0:
        sliceLabel.text = "Vacant"
    case 1:
        sliceLabel.text = "Vacant Uncheck Clean"
    case 2:
        sliceLabel.text = "Occupied Cleaned"
    return sliceLabel


func sChart(_ chart: ShinobiChart, seriesAt index: Int) -> SChartSeries {
    let chart = SChartDonutSeries()
    chart.style().spokeStyle.showSpokes = true;
    chart.selectedStyle().spokeStyle.showSpokes = true;
    chart.style().labelFontColor = UIColor.black
    chart.selectedStyle().labelFontColor = UIColor.black
    return chart

Thanks for suggest :slight_smile:


Hi aclarke,

I’m using Swift 3, the statement chart.plotAreaBackgroundColor = .clear is give error the plotAreaBackgroundColor is method or plotAreaBackgroundColor() . So i cant use that, is there any way to make background of the chart transparent?



Hi Mario,

Please can you double-check you’re using the property plotAreaBackgroundColor (note the Area) rather than the method plotBackgroundColor ?

I’m also using Swift 3 and setting both chart.backgroundColor and the chart.plotAreaBackgroundColor to .clear does make the background transparent.