title: Swift chart library. How to display X axis dates in a right places
body: <p><strong>EDITED: This is a debug <a href="https://youtu.be/8EMA4bnBIPs" rel="nofollow noreferrer">video</a> as well.</strong></p>
  
  <p>I use this <a href="https://github.com/danielgindi/Charts" rel="nofollow noreferrer">library</a> to show charts in my Swift iOS app. This is my chart:</p>
  
  <p><a href="https://i.stack.imgur.com/73zNg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/73zNg.png" alt="enter image description here"></a></p>
  
  <p>X axis is for dates and Y axis is for lifted weight for my athletes.</p>
  
  <p>The ocean blue dots in the middle of the charts that you see it is an intersection between a date and lifted weight. But I am not sure how a chart shows two the same dates and a dot at the middle of dates.</p>
  
  <p>My question is how can I set up X axis to shift Aug 23 to the middle of the screen as well or to fit a dot I don't care should it be shifted or not, I just want to show a dot in the same line of date. Like on image below:</p>
  
  <p><a href="https://i.stack.imgur.com/BgaSV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BgaSV.png" alt="enter image description here"></a></p>
  
  <p>The idea is to show dates under all dots, instead of flexible X axis which right now shows some range of time between one date.</p>
  
  <p>This is my code as you can see I loop my result and create dates list from it and total lifted weight for Y axis. Dates are retrieved from <code>dateValue.timeIntervalSince1970</code></p>
  
  <pre><code>func setupGraphicWithResults(_ results: [ExerciseSetResult]) {
  
          var oneRMValuesList = [Double]()
          var dateList = [Int]()
  
          for exerciseResult in prepareResults(results) {           
              let oneRMValue = ExeciseResultsService().calculateOneRMValueForResult(exerciseResult)
              let formattedOneRMValue = UnitMeasurementService().convertWeightValueToCurrentMeasurementUnit(oneRMValue)
              oneRMValuesList.append(formattedOneRMValue)
  
              let dateValue = exerciseResult.date.formatStringToDate()
              let dateInt = dateValue.timeIntervalSince1970
              dateList.append(Int(dateInt))
          }
  
          setChart(datePoints: dateList, values: oneRMValuesList)
      }
  
  
  func setChart(datePoints: [Int], values: [Double]) {
  
          let yAxis = chartView.leftAxis
          yAxis.labelFont = UIFont.mainAppFont(11)
          yAxis.setLabelCount(5, force: true)
          yAxis.labelTextColor = .white
          yAxis.labelPosition = .outsideChart
          yAxis.axisLineColor = .stackedTipTextColor
          yAxis.granularity = 5.0
          yAxis.granularityEnabled = true
          yAxis.drawGridLinesEnabled = true
          yAxis.drawAxisLineEnabled = false
  
          let xAxis = chartView.xAxis
          xAxis.labelFont = UIFont.mainAppFont(11)
          xAxis.labelTextColor = .white
          xAxis.labelPosition = .bottom
          xAxis.drawAxisLineEnabled = false
          xAxis.drawGridLinesEnabled = false
          xAxis.setLabelCount(datePoints.count, force: true)
          xAxis.valueFormatter = DateValueFormatter()
          xAxis.yOffset = 20.0
  
          chartView.rightAxis.enabled = false
          chartView.legend.enabled = false
          chartView.chartDescription?.enabled = false
          chartView.setExtraOffsets(left: 10, top: 0, right: 20, bottom: 0)
  
          var dataEntries: [ChartDataEntry] = []
  
          for i in 0..&lt;values.count {
              let dataEntry = ChartDataEntry(x: Double(datePoints[i]), y: values[i])
              dataEntries.append(dataEntry)
          }
  
          let lineChartDataSet = LineChartDataSet(entries: dataEntries, label: "")
  
          lineChartDataSet.mode = .cubicBezier
          lineChartDataSet.drawCirclesEnabled = true
          lineChartDataSet.lineWidth = 2.8
          lineChartDataSet.circleRadius = 4
          lineChartDataSet.circleHoleRadius = 3.8
          lineChartDataSet.circleHoleColor = .stackedLightBlue
          lineChartDataSet.setCircleColor(.white)
          lineChartDataSet.highlightColor = .stackedLightBlue
          //lineChartDataSet.fillColor = .stackedLightBlue
          //lineChartDataSet.fillAlpha = 0.2
          lineChartDataSet.drawFilledEnabled = true
          lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = false
          lineChartDataSet.drawVerticalHighlightIndicatorEnabled = false
  
          let gradientColors = [UIColor.stackedLightBlue.cgColor, UIColor.clear.cgColor] as CFArray // Colors of the gradient
          let colorLocations:[CGFloat] = [1.0, 0.0] // Positioning of the gradient
          let gradient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: gradientColors, locations: colorLocations) // Gradient Object
          lineChartDataSet.fill = Fill.fillWithLinearGradient(gradient!, angle: 90.0)
  
          let lineChartData = LineChartData(dataSet: lineChartDataSet)
  
          lineChartData.setDrawValues(false)
          chartView.data = lineChartData
      }
  </code></pre>