SwiftUICharts
SwiftUICharts copied to clipboard
Pie Charts with gradients
Would it be possible to handle gradients colors within Pie or Doughnut Charts ? Something like that?

Hi @willdale! So I managed to get the result I wanted (by duplicating the code) !

Both the fill of the PieChart and the stroke of the DoughnutChart accept a Color or a Gradient.
I wanted to make a PR, but I have the following problems:
- How to allow both
ColorandGradientin the related datapoints? If I changepublic var colour: ColorinPieChartDataPointbypublic var colour: ShapeStyle, I get the errorProtocol 'ShapeStyle' can only be used as a generic constraint because it has Self or associated type requirements. - The gradient may actually need the
startAngleandamountof the data point itself, if we want to be able to useRadialGradientas in my example:
Here is an example of a modified version of PieChart.
PieSegmentShape(id: chartData.dataSets.dataPoints[data].id,
startAngle: chartData.dataSets.dataPoints[data].startAngle,
amount: chartData.dataSets.dataPoints[data].amount)
.fill(AngularGradient(
gradient: Gradient(colors: [
Color(DynamicColor(chartData.dataSets.dataPoints[data].colour).lighter(amount: 0.3)),
Color(DynamicColor(chartData.dataSets.dataPoints[data].colour).darkened(amount: 0.1))
]),
center: .center,
startAngle: .radians(chartData.dataSets.dataPoints[data].startAngle),
endAngle: .radians(chartData.dataSets.dataPoints[data].startAngle+chartData.dataSets.dataPoints[data].amount)
))
Could you help me with this? What would be the preferred way to handle this case?