willdale / SwiftUICharts

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.
MIT License
860 stars 108 forks source link

Suggestion/Request - Pie Chart values < 0 #53

Closed kennedycraig closed 3 years ago

kennedycraig commented 3 years ago

When pie charts are fed values < 0 (e.g. decimals representing % summing to 1.0) the touch info box value is rounded to an int 0. Fixed by just multiplying by 100 in the case of a percentage in the view code.

Would be nice to be able to: 1) Feed in a specifier to allow for formatting of the info box number in the intended format.

Unrelated - would be nice to be able to label the slices in a way that did not require touch to display the slice value.

Food for thought.

willdale commented 3 years ago

Decimal

Decimal precision is possible currently.

PieChart(chartData: data)
    .touchOverlay(chartData: data, specifier: "%.01f")
PieDataSet(dataPoints: [
            PieChartDataPoint(value: 0.7, description: "One",   colour: .blue),
            PieChartDataPoint(value: 0.2, description: "Two",   colour: .red),
            PieChartDataPoint(value: 0.9, description: "Three", colour: .purple),
            PieChartDataPoint(value: 0.6, description: "Four",  colour: .green),
            PieChartDataPoint(value: 0.4, description: "Five",  colour: .orange)],
           legendTitle: "Data")

Decimal precision in pie chart


Segment Labels

I've add this to a "To Do" project.

kennedycraig commented 3 years ago

Thanks, Will.

willdale commented 3 years ago

No worries.

willdale commented 3 years ago

This has been added in v2.5.0.

 PieChartDataPoint(value: 7, description: "One", colour: .blue, label: .icon(systemName: "1.square", colour: .white, size: 30))

Thanks, Will

Edit: Test

kennedycraig commented 3 years ago

Perfectly brilliant! Thanks, Will!