gpt4 book ai didi

swift - Shinobi donut chart 表标签颜色不会改变

转载 作者:行者123 更新时间:2023-11-28 08:21:33 26 4
gpt4 key购买 nike

我有一个 Shinobi 圆环图,我想为其更改切片标签颜色。

我使用 Swift3。图表显示完美,但标签颜色为白色。

class myViewController: UIViewController, SChartDatasource {

@IBOutlet weak var paymentChartView: UIView!

override func viewDidLoad() {
addPaymentInformationChart()
}

func addPaymentInformationChart() {
let chart = ShinobiChart(frame: paymentChartView.bounds)
chart.title = "Payment Information"
chart.autoresizingMask = [.flexibleHeight, .flexibleWidth]
chart.titleLabel.textColor = UIColor.black

chart.datasource = self
paymentChartView.addSubview(chart)
}

/* SChartDatasource methods */

func numberOfSeries(in chart: ShinobiChart) -> Int {
return 1
}

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

func sChart(_ chart: ShinobiChart, numberOfDataPointsForSeriesAt seriesIndex: Int) -> Int {
return 3
}

func sChart(_ chart: ShinobiChart, dataPointAt dataIndex: Int, forSeriesAt seriesIndex: Int) -> SChartData {
let dp = SChartDataPoint()
dp.xValue = 0
dp.yValue = 0
if paymentDatasource.count > 0 {
switch dataIndex {
case 0:
dp.yValue = 100.0
break
case 1:
dp.yValue = 200.0
break
case 2:
dp.yValue = 300.0
break
default:
break
}
}
return dp
}

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

let sliceLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
sliceLabel.textColor = UIColor.black

switch sliceIndex {
case 0:
sliceLabel.text = "Principal"
break
case 1:
sliceLabel.text = "Interest"
break
case 2:
sliceLabel.text = "Total"
break
default:
break
}
return sliceLabel
}

}

标签文本设置正确,但标签颜色不会改变。

enter image description here

如果有任何帮助,我将不胜感激

最佳答案

毕竟我发现我必须更改图表样式才能更改标签样式:

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

关于swift - Shinobi donut chart 表标签颜色不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41173080/

26 4 0