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

Bars not showing BarChart #4337

Closed
AhmAbdallah opened this issue Apr 13, 2020 · 1 comment
Closed

Bars not showing BarChart #4337

AhmAbdallah opened this issue Apr 13, 2020 · 1 comment

Comments

@AhmAbdallah
Copy link

Screen Shot 2020-04-13 at 13 45 33

I used the chart in my old app and now we are updating it to Swift 5, unfortunately, I am passing the data in the correct way but now change on the chart view.

extension blalbla {
func setupBarView() {
    countView.text = ""
    barView.delegate = self
    barView.setVisibleXRange(minXRange: 1, maxXRange: 10)
    barView.backgroundColor = UIColor.white
    barView.leftAxis.enabled = false
    barView.rightAxis.enabled = false
    barView.xAxis.enabled = false
    barView.xAxis.drawGridLinesEnabled = false
    barView.xAxis.labelPosition = .bottom
    barView.xAxis.valueFormatter = self
    barView.xAxis.granularity = 1.0
    barView.noDataText = "Grafik verisi mevcut değil"
    // Refresh chart with new data
    barView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    barView.notifyDataSetChanged()
  }
  func barChartUpdate() {
    barView.data = nil
    barChartEntry = []
    monthTitles = []
    for item in 0..<babyKickCountVM!.getBabyKickCount() {
      let calendar = Calendar.current
      let dateFormatter = DateFormatter()
      dateFormatter.dateFormat = "dd-MM-yyyy"
      let date = dateFormatter.date(from: babyKickCountVM!.getBabyKickDateFor(index: item))
      //let year = calendar.component(.year, from: date!)
      let month = calendar.component(.month, from: date!)
      let day = calendar.component(.day, from: date!)
      monthTitles.append("\(day) \(months[month - 1])")
      print("item: \(Double(item))")
      print("item2: \(Double(babyKickCountVM!.getBabyKickCountFor(index: item)))")
      let entry = BarChartDataEntry(x: Double(item), y: Double(babyKickCountVM!.getBabyKickCountFor(index: item)))
      barChartEntry.append(entry)
    }
    barView.chartDescription?.text = "Empty data"
    let dataSet = BarChartDataSet(entries: barChartEntry, label: "TEKME SAYAR")
    let data = BarChartData(dataSets: [dataSet])
    dataSet.colors = [UIColor.jokerColor]
    dataSet.barBorderColor = UIColor.jokerColor
    dataSet.barBorderWidth = 30
    data.barWidth = 0.9
 
    barView.data = data
    barView.chartDescription?.text = ""
    count = babyKickCountVM!.getBabyKickCountForToday()
    countView.text = "\(count)"
    barView.data?.notifyDataChanged()
  }
}
@AhmAbdallah
Copy link
Author

I solved it by removing these two lines
//barView.setVisibleXRange(minXRange: 1, maxXRange: 100)
//barView.xAxis.enabled = false

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