Pie Chart entries outside slices have different position offsets

懵懂的女人 提交于 2019-12-13 03:58:02

问题


The Charts library I'm using: Daniel Gindi - Charts

If you look at the above image, the position offset of entries outside each slice are variable both in distance from the slice as well as in alignment.

What I want:

  1. Align the entry text to be at the center outside the slice. [Look at 1 & 3]
  2. Keep all the slice texts equidistant from the slice. [Look at 3 & 6]

What I tried so far:

I tried to play with valueLinePart1Length and valueLinePart2Length, but this just helped a little, didn't solve the problem completely. Also I went through all the variables of PieChartDataSet.

Still haven't figured out how to fix this, can someone point out am I missing something or how to fix the issue.

Edit: Added code

let values: [Double] = [16, 6, 1, 3]
let chartEntries: [PieChartDataEntry] = pieChartEntries(for: values)
let pieChartDataSet = PieChartDataSet(values: chartEntries, label: nil)

pieChartDataSet.sliceSpace = 2
pieChartDataSet.colors = colors
pieChartDataSet.valueLineWidth = 0
pieChartDataSet.valueLinePart1Length = 0.4
pieChartDataSet.valueLinePart2Length = 0
pieChartDataSet.valueTextColor = .black
pieChartDataSet.yValuePosition = .outsideSlice
pieChartDataSet.valueLineVariableLength = false

let pieChartData = PieChartData(dataSet: pieChartDataSet)
pieChart.data = pieChartData

来源:https://stackoverflow.com/questions/51453836/pie-chart-entries-outside-slices-have-different-position-offsets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!