title: Stacked bar chart with charts in Swift
body: <p>I am trying to build a stacked bar chart with the Charts framework (Swift) in my iOS project. All I can build at the moment is a grouped bar chart. Does someone know how to do this?</p>
  
  <p>All I found is: <a href="https://stackoverflow.com/questions/31309085/convert-bar-chart-to-a-grouped-bar-chart-with-danielgindi-ios-charts-and-swift">Convert bar chart to a grouped bar chart with danielgindi/ios-charts and Swift</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>@IBOutlet var barChartView: BarChartView!
  var receivedDate1 : String = ""
  var receivedDate2 : String = ""
  var receivedDate3 : String = ""
  var receivedDate4 : String = ""
  var receivedDate5 : String = ""
  
  var months: [String]!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      months = [receivedDate1, receivedDate2, receivedDate3, receivedDate4, receivedDate5]
      let dominanz1 = [1.0, 2.0, 3.0, 4.0, 5.0]
      let dominanz2 = [5.0, 4.0, 3.0, 2.0, 1.0]
  
      setChartBarGroupDataSet(months, values: dominanz1, values2: dominanz2, sortIndex: 1)
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  func setChartBarGroupDataSet(dataPoints: [String], values: [Double], values2: [Double],sortIndex:Int) {
  
      var dataEntries: [BarChartDataEntry] = []
      var dataEntries2: [BarChartDataEntry] = []
  
  
      for i in 0..&lt;dataPoints.count {
  
          let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
          dataEntries.append(dataEntry)
      }
  
  
      for i in 0..&lt;dataPoints.count {
  
          let dataEntry = BarChartDataEntry(value: values2[i], xIndex: i)
          dataEntries2.append(dataEntry)
      }
  
  
      let chartDataSet = BarChartDataSet(yVals: dataEntries, label: " ")
      let chartDataSet2 = BarChartDataSet(yVals: dataEntries2, label: " ")
  
      chartDataSet2.colors =  [UIColor(red: 255/255, green: 70/255, blue: 108/255, alpha: 1)]
  
      chartDataSet.colors =  [UIColor(red: 49/255, green: 27/255, blue: 146/255, alpha: 1)]
  
  
      let dataSets: [BarChartDataSet] = [chartDataSet,chartDataSet2]
  
      let data = BarChartData(xVals: dataPoints, dataSets: dataSets)
  
      barChartView.data = data
  
      barChartView.descriptionText = ""
  
  
      barChartView.rightAxis.drawGridLinesEnabled = false
      barChartView.rightAxis.drawAxisLineEnabled = false
      barChartView.rightAxis.drawLabelsEnabled = false
  
  
      barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .EaseInBounce)
  
  
  }
  </code></pre>
  
  <p>The Framework I use is Charts 2.2.4 from cocoapods.
  This is what it currently looks like: <a href="https://i.stack.imgur.com/LMseo.png" rel="nofollow noreferrer">grouped bar chart</a>
  And this is how it should look like: <a href="https://i.stack.imgur.com/f5TOq.png" rel="nofollow noreferrer">stacked bar chart</a></p>