title: Many Gradient Fill in same lineChart Swift for iOS-Charts
body: <pre><code>let gradientColors = [UIColor.cyanColor().CGColor, UIColor.clearColor().CGColor] // Colors of the gradient
  let colorLocations:[CGFloat] = [1.0, 0.0] // Positioning of the gradient
  let gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), gradientColors, colorLocations) // Gradient Object
  set.fill = ChartFill.fillWithLinearGradient(gradient!, angle: 90.0) // Set the Gradient
  set.drawFilledEnabled = true // Draw the Gradient
  </code></pre>
  
  <p>Result</p>
  
  <p><img src="https://i.stack.imgur.com/EHYQ2.png" alt="chart-fill"></p>
  
  <p>I want to have many fill depending of xAxis value like this :</p>
  
  <p><a href="https://i.stack.imgur.com/bbq67.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bbq67.png" alt="enter image description here"></a></p>
  
  <p>It's possible to do this ??</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>The solution is to use many dataset, from the second one, the first value for each data need to be same the last value of the previous dataset so at the end it will look like you have one dataset</p>
  
  <p>ex: </p>
  
  <pre><code>let dollars1 = [1453.0,2352,5431,1442] // last value = first value of next dataset
  let dollars2 = [1442.0,2234,8763,4453] // last value = first value of next dataset
  let dollars3 = [4453.0,3456,7843,5678] // last value = first value of next dataset
  
  func setChartData(months : [String]) {
  
      var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
      for var i = 0; i &lt; months.count; i++ {
          yVals1.append(ChartDataEntry(value: dollars1[i], xIndex: i))
      }
  
      let set1: LineChartDataSet = LineChartDataSet(yVals: yVals1, label: "First Set")
      set1.axisDependency = .Left // Line will correlate with left axis values
      set1.setColor(UIColor.redColor().colorWithAlphaComponent(0.5))
      set1.setCircleColor(UIColor.redColor())
      set1.lineWidth = 2.0
      set1.circleRadius = 6.0
      set1.fillAlpha = 1
      set1.fillColor = UIColor.redColor()
      set1.drawFilledEnabled = true
  
      var yVals2 : [ChartDataEntry] = [ChartDataEntry]()
      for var i = 0; i &lt; months.count; i++ {
          yVals2.append(ChartDataEntry(value: dollars2[i], xIndex: i))
      }
  
      let set2: LineChartDataSet = LineChartDataSet(yVals: yVals2, label: "Second Set")
      set2.axisDependency = .Left // Line will correlate with left axis values
      set2.setColor(UIColor.greenColor().colorWithAlphaComponent(0.5))
      set2.setCircleColor(UIColor.greenColor())
      set2.lineWidth = 2.0
      set2.circleRadius = 6.0
      set2.fillAlpha = 1
      set2.fillColor = UIColor.greenColor()
      set2.drawFilledEnabled = true
  
      var yVals3 : [ChartDataEntry] = [ChartDataEntry]()
      for var i = 0; i &lt; months.count; i++ {
          yVals3.append(ChartDataEntry(value: dollars3[i], xIndex: i))
      }
  
      let set3: LineChartDataSet = LineChartDataSet(yVals: yVals3, label: "Second Set")
      set3.axisDependency = .Left // Line will correlate with left axis values
      set3.setColor(UIColor.blueColor().colorWithAlphaComponent(0.5))
      set3.setCircleColor(UIColor.blueColor())
      set3.lineWidth = 2.0
      set3.circleRadius = 6.0
      set3.fillAlpha = 65 / 255.0
      set3.fillColor = UIColor.blueColor()
      set3.drawFilledEnabled = true
  
      //3 - create an array to store our LineChartDataSets
      var dataSets : [LineChartDataSet] = [LineChartDataSet]()
      dataSets.append(set1)
      dataSets.append(set2)
      dataSets.append(set3)
  
      //4 - pass our months in for our x-axis label value along with our dataSets
      let data: LineChartData = LineChartData(xVals: months, dataSets: dataSets)
      data.setValueTextColor(UIColor.whiteColor())
  
      //5 - finally set our data
      self.lineChartView.data = data
  
  }
  </code></pre>