Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar Chart shows columns as full when no data is present #259

Open
tmaasen opened this issue Feb 24, 2023 · 0 comments
Open

Bar Chart shows columns as full when no data is present #259

tmaasen opened this issue Feb 24, 2023 · 0 comments

Comments

@tmaasen
Copy link

tmaasen commented Feb 24, 2023

When there's no data in the bar chart, all the columns show as if they are full. However, as soon as I add a real positive number to any bar, the entire chart shows correctly with 1 bar having data and the rest are empty.

Screenshot 2023-02-24 at 5 45 57 PM

Description

Here's the code. There's a chance something might be wrong with the config of the chart?
I also tried test data (0's) to confirm it wasn't a problem with the variables, but it shows the same issue.
I'm on v2.0.0-beta.2

struct Analytics_Graph1: View {
    var viewModel: AnalyticsViewModel    
    @State private var g1HappyMoods: Double = 0
    @State private var g1NeutralMoods: Double = 0
    @State private var g1SickMoods: Double = 0
    @State private var g1OverateMoods: Double = 0
    @State private var g1TotalDataPoints: Int = 0

    let multiStyle = ChartStyle(backgroundColor: Color.green.opacity(0.2),
                                foregroundColor:
                                    [ColorGradient(.purple, .blue),
                                     ColorGradient(.orange, .red),
                                     ColorGradient(.green, .yellow),
                                     ColorGradient(.red, .purple),
                                     ColorGradient(.yellow, .orange),
                                    ])
    
    var body: some View {
            ZStack(alignment: .center) {
                CardView {
                    BarChart()
                }
                .data(
                    [((Mood.happy.text+Mood.happy.emoji), g1HappyMoods),
                     ((Mood.neutral.text+Mood.neutral.emoji), g1NeutralMoods),
                     ((Mood.sick.text+Mood.sick.emoji), g1SickMoods),
                     ((Mood.overate.text+Mood.overate.emoji), g1OverateMoods)
                    ])
                .chartStyle(multiStyle)
                .onAppear() {
                    getData()
                }
            }
            .padding()
    }
    func getData() {
        viewModel.getData(completion: { moods in
            g1TotalDataPoints = Int(moods[0])
            g1HappyMoods = moods[1]
            g1NeutralMoods = moods[2]
            g1SickMoods = moods[3]
            g1OverateMoods = moods[4]
        })
    }
}

Your Environment

  • Version of this package used: v2.0.0-beta.2
  • Device/Simulator: iPhone 12 Pro simulator, iPhone 13 device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant