       .map { $0.lineChartData }
       .drive(onNext: { [weak self] dataPoints in
         guard let strongSelf = self else { return }
-
-        guard let data = strongSelf.lineChart.data,
-          let dataSet = data.getDataSetByIndex(0) else {
-            return
-        }
-
-        dataSet.clear()
-
-        for point in dataPoints {
-          let x = point.time.timeIntervalSince1970
-          let y = point.value
-
-          let yDataEntry = ChartDataEntry(x: x, y: y)
-          data.addEntry(yDataEntry, dataSetIndex: 0)
-        }
-
-        dataSet.notifyDataSetChanged()
-        data.notifyDataChanged()
-        strongSelf.lineChart.notifyDataSetChanged()
+        strongSelf.updateLineChartData(dataPoints)
         })
       .addDisposableTo(self.disposeBag)
 

      .map { $0.barChartData }
      .drive(onNext: { [weak self] dataPoints in
        guard let strongSelf = self else { return }

        guard let data = strongSelf.barChart.data,
          let dataSet = data.getDataSetByIndex(0) else {
            return
        }

        dataSet.clear()

        for point in dataPoints {
          // 'x' here means the offset in days from 'today'
          let x = floor(point.time.timeIntervalSinceNow / 86400)
          let y = point.value

          let yDataEntry = BarChartDataEntry(x: x, y: y)
          data.addEntry(yDataEntry, dataSetIndex: 0)
        }

        dataSet.notifyDataSetChanged()
        data.notifyDataChanged()
        strongSelf.barChart.notifyDataSetChanged()
        })
      .addDisposableTo(self.disposeBag)


    yAxis.drawAxisLineEnabled = false
    yAxis.labelTextColor = .black

    let data = LineChartData()
    lineChart.data = data
  }

