title: iOS Charts: Showing actual value with percentage inside PieChart?
body: <p>I'm currently using <a href="https://github.com/danielgindi/Charts" rel="nofollow noreferrer">Charts - by Daniel Gindi</a>, and following his demo, I've implemented a PieChart like so:</p>
  
  <p><a href="https://i.stack.imgur.com/Nks3o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nks3o.png" alt="enter image description here"></a></p>
  
  <p>It was achieve using the following code:</p>
  
  <pre><code>func createPieChart(dataPoints: [String: Double])
  {
      for index in 0..&lt;sortedDates.count
      {
          let year = sortedDates[index]
  
          guard let costs = dataPoints[year] else {
              return
          }
  
          let dataEntry = PieChartDataEntry(value: costs, label: year)
  
          dataEntries.append(dataEntry)
      }
  
      chartDataSet = PieChartDataSet(values: dataEntries, label: "")
  
      chartData = PieChartData(dataSet: chartDataSet)
  
      chartDataSet.sliceSpace = 2.0
  
      chartDataSet.yValuePosition = PieChartDataSet.ValuePosition.outsideSlice
  
      ...
  
      pieChartView.usePercentValuesEnabled = true
      pieChartView.drawSlicesUnderHoleEnabled = false
      pieChartView.holeRadiusPercent = 0.40
      pieChartView.transparentCircleRadiusPercent = 0.43
      pieChartView.drawHoleEnabled = true
      pieChartView.rotationAngle = 0.0
      pieChartView.rotationEnabled = true
      pieChartView.highlightPerTapEnabled = false
  
      let pieChartLegend = pieChartView.legend
      pieChartLegend.horizontalAlignment = Legend.HorizontalAlignment.right
      pieChartLegend.verticalAlignment = Legend.VerticalAlignment.top
      pieChartLegend.orientation = Legend.Orientation.vertical
      pieChartLegend.drawInside = false
      pieChartLegend.yOffset = 10.0
  
      pieChartView.legend.enabled = true
  
      pieChartView.data = chartData
  }
  </code></pre>
  
  <p>What I'm trying to achieve is to show the actual <code>costs</code> value inside the pie slice, but also include the percentage outside the slice. The percentage is shown using <code>chartDataSet.yValuePosition = PieChartDataSet.ValuePosition.outsideSlice</code>.</p>
  
  <p>Inspecting the code, I noticed that in <code>PieChartRenderer</code>, there is there function <code>open override func drawValues(context: CGContext)</code> and within it, the code calculates the percentage of each pie slice in <code>valueText</code>:</p>
  
  <pre><code>let valueText = formatter.stringForValue(
                      value,
                      entry: e,
                      dataSetIndex: i,
                      viewPortHandler: viewPortHandler)
  </code></pre>
  
  <p>Then using an <code>if</code> check, it draws the percentage inside or outside the slice, which in my case is outside:</p>
  
  <pre><code>else if drawYOutside
  {
      ChartUtils.drawText(
                          context: context,
                          text: valueText,
                          point: CGPoint(x: 0, y: labelPoint.y + lineHeight / 2.0),
                          align: align,
                          attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: valueTextColor]
                          )
  }
  </code></pre>
  
  <p>However, I can't find a way to actual include the <code>costs</code> value that is passed into <code>PieChartDataEntry(value: costs, label: year)</code>.</p>
  
  <p>I was told to subclass the Pie Chart and override the methods I found but I'm not exactly sure how to do that.</p>
  
  <p>For example, the value of <code>costs</code> at each index in <code>dataPoints</code> is a double value of <code>100.0</code> for the label <code>2017</code> and <code>50.0</code> for the label <code>2016</code>. I would like to include both those values in the associated pie slice.</p>
  
  <p>Can anyone experienced with this library assist me?</p>
  
  <p>Thanks!</p>