Can I show all the markers without clicking on a bar?
currently, I need to tap on any of the bar and it'll only show the one that is clicked. I'm trying to add a marker on each of the green bar and showing all without any bar being clicked. Is it possible?
Edit:
Below is my code changed from the github demo code
(PillMarker came from this)
import Charts
import UIKit
class BarChartViewController: DemoBaseViewController {
#IBOutlet var chartView: BarChartView!
#IBOutlet var sliderX: UISlider!
#IBOutlet var sliderY: UISlider!
#IBOutlet var sliderTextX: UITextField!
#IBOutlet var sliderTextY: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.options = [.animateY]
self.setup(barLineChartView: chartView)
chartView.delegate = self
chartView.drawBarShadowEnabled = false
chartView.drawValueAboveBarEnabled = false
chartView.maxVisibleCount = 60
chartView.dragEnabled = false
chartView.scaleXEnabled = false
chartView.scaleYEnabled = false
chartView.leftAxis.drawAxisLineEnabled = false
chartView.xAxis.drawGridLinesEnabled = false
chartView.legend.enabled = false
let xAxis = chartView.xAxis
xAxis.labelPosition = .bottom
xAxis.labelFont = .systemFont(ofSize: 10)
xAxis.labelTextColor = .green
xAxis.granularity = 1
xAxis.labelCount = 7
xAxis.valueFormatter = DayAxisValueFormatter(chart: chartView)
let leftAxis = chartView.leftAxis
leftAxis.labelFont = .systemFont(ofSize: 10)
leftAxis.labelTextColor = .red
leftAxis.labelCount = 8
leftAxis.labelPosition = .outsideChart
leftAxis.spaceTop = 0.15
leftAxis.axisMinimum = 0
let l = chartView.legend
l.horizontalAlignment = .left
l.verticalAlignment = .bottom
l.orientation = .horizontal
l.drawInside = false
l.form = .square
l.formSize = 9
l.font = UIFont(name: "HelveticaNeue-Light", size: 11)!
l.textColor = .blue
l.xEntrySpace = 4
//Marker
let marker = PillMarker(color: .white, font: UIFont.boldSystemFont(ofSize: 14), textColor: .black)
chartView.marker = marker
sliderX.value = 12
sliderY.value = 50
slidersValueChanged(nil)
}
override func updateChartData() {
if self.shouldHideData {
chartView.data = nil
return
}
self.setDataCount(1, range: UInt32(sliderY.value))
}
func setDataCount(_ count: Int, range: UInt32) {
let start = 1
let yVals = (start..<start+count+1).map { (i) -> BarChartDataEntry in
let mult = range + 1
let val = Double(arc4random_uniform(mult))
return BarChartDataEntry(x: Double(i), y: val)
}
var set1: BarChartDataSet! = nil
if let set = chartView.data?.first as? BarChartDataSet {
set1 = set
set1.replaceEntries(yVals)
chartView.data?.notifyDataChanged()
chartView.notifyDataSetChanged()
} else {
set1 = BarChartDataSet(entries: yVals, label: "The year 2017")
set1.colors = ChartColorTemplates.material()
set1.highlightColor = NSUIColor(red: 46/255.0, green: 204/255.0, blue: 113/255.0, alpha: 1.0)
set1.drawValuesEnabled = false
set1.drawIconsEnabled = true
let data = BarChartData(dataSet: set1)
data.setValueFont(UIFont(name: "HelveticaNeue-Light", size: 10)!)
data.barWidth = 0.3
chartView.data = data
}
}
Yes, You can show all marker on bar.
put marker code with bar drawing code.
Related
I am using the iOS Charts library for the candlestick chart, I not able to find any way to draw custom views that is a triangle as shown in the image library.
I want to show the triangle(view) on the top and bottom of the candle based on the flag.
If this is not possible in Charts library please let me know the alternate library where I can achieve this.
CandleSitckChart
{
chartView.delegate = self
chartView.chartDescription?.enabled = true
chartView.drawBordersEnabled = false
chartView.drawGridBackgroundEnabled = false
chartView.xAxis.labelTextColor = .white
chartView.rightAxis.labelTextColor = .white
chartView.dragEnabled = true
chartView.setScaleEnabled(true)
chartView.pinchZoomEnabled = true
chartView.drawMarkers = true
chartView.legend.enabled = false
chartView.leftAxis.enabled = false
chartView.leftAxis.spaceTop = 0.3
chartView.leftAxis.spaceBottom = 0.3
chartView.leftAxis.axisMinimum = 0
chartView.rightAxis.enabled = true
chartView.rightAxis.axisLineColor = .primaryBlue
chartView.drawGridBackgroundEnabled = false
let candleResponse = MasterData.shared.candleResponse
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "h:mm a"
let dates = candleResponse
.map { Date(timeIntervalSince1970: ($0.first ?? 0)/1000) }
.map { dateFormatter.string(from: $0) }
chartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: dates)
chartView.xAxis.labelPosition = .bottom
let yVals1 = (0..<candleResponse.count).map { (i) -> CandleChartDataEntry in
return CandleChartDataEntry(x: Double(i),
shadowH: candleResponse[i][2],
shadowL: candleResponse[i][3],
open: candleResponse[i][1],
close: candleResponse[i][4])
}
let set1 = CandleChartDataSet(entries: yVals1)
set1.setDrawHighlightIndicators(true)
set1.drawVerticalHighlightIndicatorEnabled = true
set1.drawHorizontalHighlightIndicatorEnabled = true
set1.axisDependency = .right
set1.setColor(UIColor(white: 80/255, alpha: 1))
set1.drawIconsEnabled = true
set1.shadowColor = .darkGray
set1.shadowWidth = 0.7
set1.decreasingColor = .red
set1.decreasingFilled = true
set1.increasingColor = UIColor(red: 122/255, green: 242/255, blue: 84/255, alpha: 1)
set1.increasingFilled = true
set1.neutralColor = .blue
let data = CandleChartData(dataSet: set1)
data.setDrawValues(false)
chartView.data = data
}
I am writing an iOS App in Swift 4.2. I am using Charts Library to display Horizontal Bar chart. When I open the sample project, it shows the Y Values but, in my project it isn't showing the Y values. I copied the exact code from its sample.
Sample screenshot:
Observe 8.0, 14.0, 4.0, 10.0
My screenshot:
My Code:
#IBOutlet weak var chartView: HorizontalBarChartView!
func setupCharts(){
chartView.noDataTextColor=UIColor(hex:UIConstants.Graphics.BrandTheme.ThemeColor)
chartView.noDataText = "Chart_NoDataText".localized
chartView.chartDescription?.enabled = false
chartView.dragEnabled = false
chartView.setScaleEnabled(true)
chartView.pinchZoomEnabled = false
//chartView.delegate = self
chartView.drawBarShadowEnabled = false
chartView.drawValueAboveBarEnabled = true
chartView.maxVisibleCount = 60
chartView.setVisibleXRangeMaximum(4)
chartView.drawGridBackgroundEnabled=false
chartView.extraRightOffset=CGFloat(24)
chartView.isUserInteractionEnabled = false
chartView.legend.enabled=false
chartView.fitBars = true
let xAxis = chartView.xAxis
xAxis.labelPosition = .bottom
xAxis.labelFont = UIFont(name: "Lato-Regular", size: 11)!
xAxis.drawAxisLineEnabled = false
xAxis.drawGridLinesEnabled = false
xAxis.granularity = 1
xAxis.enabled=true
//
let leftAxis = chartView.leftAxis
leftAxis.labelFont = UIFont(name: "Lato-Regular", size: 10)!
leftAxis.drawAxisLineEnabled = false
leftAxis.drawGridLinesEnabled = false
leftAxis.axisMinimum = 0
leftAxis.enabled=false
let rightAxis = chartView.rightAxis
rightAxis.labelFont = UIFont(name: "Lato-Regular", size: 10)!
rightAxis.drawAxisLineEnabled = false
rightAxis.drawGridLinesEnabled = false
rightAxis.axisMinimum = 0
rightAxis.enabled = false
}
func setChartDataWithValues(_ count: Int, values:[Double], labels:[String]) {
let yVals = (0..<count).map { (i) -> BarChartDataEntry in
let val = values[i]
return BarChartDataEntry(x: Double(i), y: val)
}
let barChartDataSet = BarChartDataSet(values: yVals, label: "MF")
barChartDataSet.drawIconsEnabled = false
barChartDataSet.colors=[UIColor(hex: UIConstants.Graphics.BrandTheme.ThemeColor)]
let data = BarChartData(dataSet: barChartDataSet)
data.setValueFont(UIFont(name:"Lato-Regular", size:10)!)
data.setValueTextColor(UIColor(hex:UIConstants.Graphics.BrandTheme.ThemeColor))
let xAxis = chartView?.xAxis
xAxis?.setLabelCount(3, force: false)
xAxis?.valueFormatter=IndexAxisValueFormatter(values: labels )
chartView?.data = data
}
Calling:
self.setChartDataWithValues(3,values:values, labels: ["Mutual Funds","Fixed Deposits","Savings Account"].reversed())
You should add data.setDrawValues(true) when you create the BarChartData:
...
let data = BarChartData(dataSet: barChartDataSet)
data.setDrawValues(true)
data.setValueFont(UIFont(name:"Lato-Regular", size:10)!)
data.setValueTextColor(UIColor(hex:UIConstants.Graphics.BrandTheme.ThemeColor))
...
For version 3.2.1 of Charts you also need to remove this line because values are not rendered if drawIconsEnabled is false
barChartDataSet.drawIconsEnabled = false
I am creating a chat layout to display cell for incoming and outgoing kind of messages. I have been able to make it work by activating and deactivating Constraints, except for the Text Message Kind. I noticed that on prepareForReuse() the constraints for outgoing cell get distorted.
I will like to know how I can fix this or a better alternative to solve the problem.
This is a video of what happens when I scroll.
TextMessageCell.swift
class TextMessageCell: ChatBaseCell {
override var viewModel: ChatCommonRepresentable? {
didSet {
guard let viewModel = viewModel as? MessageModel else {return}
let isIncoming = viewModel.isIncomming
messageLabel.text = viewModel.message
self.message = viewModel.message
sentLabel.text = viewModel.sentDateString
bubbleBackgroundView.backgroundColor = isIncoming ? .white : Color.solid08.value
messageLabel.textColor = isIncoming ? .black : .white
if isIncoming {
leadingConstraint.isActive = true
trailingConstraint.isActive = false
} else {
sentLabel.setTicker(status: viewModel.status)
leadingConstraint.isActive = false
trailingConstraint.isActive = true
}
}
}
private lazy var messageLabel: UITextViewFixed = {
let label = UITextViewFixed()
label.textAlignment = .left
label.isEditable = false
label.backgroundColor = .clear
label.isScrollEnabled = false
label.dataDetectorTypes = [.flightNumber, .calendarEvent, .address, .phoneNumber, .link, .lookupSuggestion]
label.isSelectable = true
label.isUserInteractionEnabled = true
label.delaysContentTouches = true
label.font = Font(.installed(.OpenSansRegular), size: .standard(.bodySmall)).instance
label.linkTextAttributes?[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private lazy var sentLabel: UILabel = {
let label = UILabel()
label.textAlignment = .right
label.textColor = Color.custom(hexString: "#C8CAD3", alpha: 1.0).value
label.font = Font(.installed(.OpenSansSemiBold), size: .custom(10)).instance
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private lazy var bubbleBackgroundView: UIView = {
let view = UIView()
view.layer.cornerRadius = 12
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var leadingConstraint: NSLayoutConstraint!
var trailingConstraint: NSLayoutConstraint!
var widthConstraint: NSLayoutConstraint!
var widthFullConstraint: NSLayoutConstraint!
var sentLabelBottomConstraint: NSLayoutConstraint!
var sentLabelCenterYConstraint: NSLayoutConstraint!
var messageLabelBottomConstraint: NSLayoutConstraint!
var messageLabelCenterYConstraint: NSLayoutConstraint!
var messageLabelTopConstraint: NSLayoutConstraint!
var message: String! {
didSet {
let constantHeight: CGFloat = message.height(withConstrainedWidth: 250 - 32 - 8, font: Font(.installed(.OpenSansRegular), size: .standard(.bodySmall)).instance)
let constantWidth: CGFloat = message.width(withConstrainedHeight: constantHeight, font: Font(.installed(.OpenSansRegular), size: .standard(.bodySmall)).instance)
print(constantWidth)
if constantHeight < 21 {
if constantWidth > 230 {
sentLabelCenterYConstraint.isActive = false
sentLabelBottomConstraint.isActive = true
messageLabelTopConstraint.isActive = true
messageLabelCenterYConstraint.isActive = false
messageLabelBottomConstraint.isActive = true
widthConstraint = bubbleBackgroundView.widthAnchor.constraint(lessThanOrEqualToConstant: 250)
widthConstraint.isActive = true
} else {
sentLabelCenterYConstraint.isActive = true
sentLabelBottomConstraint.isActive = false
messageLabelTopConstraint.isActive = false
messageLabelCenterYConstraint.isActive = true
messageLabelBottomConstraint.isActive = false
guard let user = UserDefaults().currentUser() else {return}
let isIncoming = "\(user.id!)" != viewModel!.sender.id
if isIncoming {
let fullWidth = constantWidth + 70
widthFullConstraint.constant = fullWidth
widthFullConstraint.isActive = true
} else {
let fullWidth = constantWidth + 90
widthFullConstraint.constant = fullWidth
widthFullConstraint.isActive = true
}
}
}
}
}
private func constraintViews() {
}
override func setupViews() {
addSubview(bubbleBackgroundView)
bubbleBackgroundView.addSubview(messageLabel)
bubbleBackgroundView.addSubview(sentLabel)
bubbleBackgroundView.topAnchor.align(to: topAnchor)
bubbleBackgroundView.bottomAnchor.align(to: bottomAnchor)
messageLabel.trailingAnchor.align(to: bubbleBackgroundView.trailingAnchor, offset: -8)
messageLabel.leadingAnchor.align(to: bubbleBackgroundView.leadingAnchor, offset: 8)
sentLabel.trailingAnchor.align(to: bubbleBackgroundView.trailingAnchor, offset: -10)
sentLabel.widthAnchor.equal(to: 70)
leadingConstraint = bubbleBackgroundView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20)
leadingConstraint.isActive = false
trailingConstraint = bubbleBackgroundView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20)
trailingConstraint.isActive = true
widthConstraint = bubbleBackgroundView.widthAnchor.constraint(lessThanOrEqualToConstant: 250)
widthConstraint.isActive = true
widthFullConstraint = bubbleBackgroundView.widthAnchor.constraint(equalToConstant: 1)
widthFullConstraint.isActive = false
messageLabelTopConstraint = messageLabel.topAnchor.constraint(equalTo: bubbleBackgroundView.topAnchor, constant: 10)
messageLabelTopConstraint.isActive = false
messageLabelBottomConstraint = bubbleBackgroundView.bottomAnchor.constraint(equalTo: bubbleBackgroundView.bottomAnchor, constant: -18)
messageLabelBottomConstraint.isActive = true
messageLabelCenterYConstraint = messageLabel.centerYAnchor.constraint(equalTo: bubbleBackgroundView.centerYAnchor)
messageLabelCenterYConstraint.isActive = false
sentLabelBottomConstraint = sentLabel.bottomAnchor.constraint(equalTo: bubbleBackgroundView.bottomAnchor, constant: -8)
sentLabelBottomConstraint.isActive = true
sentLabelCenterYConstraint = sentLabel.centerYAnchor.constraint(equalTo: bubbleBackgroundView.centerYAnchor)
sentLabelCenterYConstraint.isActive = false
}
override func prepareForReuse() {
super.prepareForReuse()
sentLabel.text = nil
messageLabel.text = nil
leadingConstraint.isActive = false
trailingConstraint.isActive = false
widthConstraint.isActive = false
sentLabelBottomConstraint.isActive = false
sentLabelCenterYConstraint.isActive = false
messageLabelBottomConstraint.isActive = false
messageLabelCenterYConstraint.isActive = false
messageLabelTopConstraint.isActive = false
widthFullConstraint.isActive = false
}
}
I want to add a line chart in UICollectionView cell by using self-created class, BaseLineChartView, which inherit from LineChartView in iOS charts API. I have to show different kinds of line charts with single line and multiple lines. So this subclass is used for getting data and setting up the chartView.
After I run the app, the cell only show chart with default noDataText. The chart doesn't show up and the change I have done in noDataText doesn't work either. But the sentence in the last line of setChart function was executed and printed in console.
Here is the code of the class:
import UIKit
import Charts
class BaseLineChartView: LineChartView {
let chartView = LineChartView()
var months = [String]()
var unitsSold = [Double]()
override init(frame: CGRect) {
super.init(frame: frame)
populateData()
lineChartSetup()
setChart(dataPoints: months, values: unitsSold)
}
func populateData(){
let _months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
let _unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0]
months = _months
unitsSold = _unitsSold
}
func lineChartSetup() {
// MARK: General
chartView.noDataText = "No Data" //Doesn't work..
chartView.chartDescription?.enabled = true
chartView.dragEnabled = false
chartView.setScaleEnabled(false)
chartView.pinchZoomEnabled = false
chartView.highlightPerDragEnabled = true
chartView.backgroundColor = .lightGray
chartView.dragXEnabled = true
chartView.dragYEnabled = false
// MARK: xAxis
let xAxis = chartView.xAxis
xAxis.labelPosition = .bottom
xAxis.labelFont = .systemFont(ofSize: 10, weight: .light)
xAxis.labelTextColor = UIColor(red: 255/255, green: 192/255, blue: 56/255, alpha: 1)
xAxis.axisLineColor = UIColor.lightGray
xAxis.drawAxisLineEnabled = true
xAxis.drawGridLinesEnabled = false
xAxis.centerAxisLabelsEnabled = false
xAxis.granularity = 1
xAxis.labelRotationAngle = -90.0
// MARK: leftAxis
let leftAxis = chartView.leftAxis
leftAxis.labelPosition = .outsideChart
leftAxis.labelFont = .systemFont(ofSize: 10, weight: .light)
leftAxis.drawGridLinesEnabled = false
leftAxis.granularityEnabled = true
leftAxis.labelTextColor = UIColor(red: 255/255, green: 192/255, blue: 56/255, alpha: 1)
// MARK: rightAxis
chartView.rightAxis.enabled = false
// MARK: legend
chartView.legend.enabled = false
// MARK: animation
chartView.animate(xAxisDuration: 1.5)
}
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry.init(x: Double(i), y: values[i])
dataEntries.append(dataEntry)
}
let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Sold")
lineChartDataSet.mode = .cubicBezier
let lineChartData = LineChartData(dataSet: lineChartDataSet)
chartView.data = lineChartData
chartView.scaleXEnabled = true
chartView.scaleYEnabled = false
chartView.setVisibleXRangeMaximum(10.0)
chartView.xAxis.setLabelCount(11, force: false)
print("Create Chart Successfully!") //Successfully show in console.
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
And I add this class into collectionView cell like this:
class DailyIndexCell: UICollectionViewCell {
let trackingChart: BaseLineChartView = {
let chartView = BaseLineChartView()
return chartView
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(trackingChart)
trackingChart.notifyDataSetChanged() //Doesn't work
self.setNeedsDisplay() //Doesn't work
setConstraints()
}
func setConstraints() {
//Add constraints of trackingChart
}
}
I've tried the solution in this post but didn't work ='(
Charts not plotting in tableViewCell
It's look like you have created property chartView in BaseLineChartView class and set various params for this property but don't use it. So for resolving your problem remove chartView property from BaseLineChartView and replace all its occurrences to self (or just remove). Also pay attantion to lines let xAxis = chartView.xAxis and let leftAxis = chartView.leftAxis you don't need to use it.
import UIKit
import Charts
class BaseLineChartView: LineChartView {
var months = [String]()
var unitsSold = [Double]()
override init(frame: CGRect) {
super.init(frame: frame)
populateData()
lineChartSetup()
setChart(dataPoints: months, values: unitsSold)
}
func populateData(){
let _months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
let _unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0]
months = _months
unitsSold = _unitsSold
}
func lineChartSetup() {
// MARK: General
noDataText = "No Data" //Doesn't work..
chartDescription?.enabled = true
dragEnabled = false
setScaleEnabled(false)
pinchZoomEnabled = false
highlightPerDragEnabled = true
backgroundColor = .lightGray
dragXEnabled = true
dragYEnabled = false
// MARK: xAxis
xAxis.labelPosition = .bottom
xAxis.labelFont = .systemFont(ofSize: 10, weight: .light)
xAxis.labelTextColor = UIColor(red: 255/255, green: 192/255, blue: 56/255, alpha: 1)
xAxis.axisLineColor = UIColor.lightGray
xAxis.drawAxisLineEnabled = true
xAxis.drawGridLinesEnabled = false
xAxis.centerAxisLabelsEnabled = false
xAxis.granularity = 1
xAxis.labelRotationAngle = -90.0
// MARK: leftAxis
leftAxis.labelPosition = .outsideChart
leftAxis.labelFont = .systemFont(ofSize: 10, weight: .light)
leftAxis.drawGridLinesEnabled = false
leftAxis.granularityEnabled = true
leftAxis.labelTextColor = UIColor(red: 255/255, green: 192/255, blue: 56/255, alpha: 1)
// MARK: rightAxis
rightAxis.enabled = false
// MARK: legend
legend.enabled = false
// MARK: animation
animate(xAxisDuration: 1.5)
}
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry.init(x: Double(i), y: values[i])
dataEntries.append(dataEntry)
}
let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Sold")
lineChartDataSet.mode = .cubicBezier
let lineChartData = LineChartData(dataSet: lineChartDataSet)
data = lineChartData
scaleXEnabled = true
scaleYEnabled = false
setVisibleXRangeMaximum(10.0)
xAxis.setLabelCount(11, force: false)
print("Create Chart Successfully!") //Successfully show in console.
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
I am trying to put labels outside properly and lines to point them but the lines are overlapping and labels at the sides are not displayed completely. If length of the line is increased the labels are cut completely.
This is what I'm getting now.
What I want is
Code:
`class ViewController: UIViewController{
let pieView : PieChartView = {
let set = PieChartView()
set.translatesAutoresizingMaskIntoConstraints = false
set.drawHoleEnabled = false
set.chartDescription?.text = ""
return set
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
navigationItem.title = "Pie"
setChart()
chartData()
}
let surveyData = ["cat": 20, "dog": 30, "both": 5, "neither": 45]
func setChart(){
view.addSubview(pieView)
pieView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
pieView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
pieView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.5).isActive = true
pieView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.5).isActive = true
}
func chartData(){
var data = [PieChartDataEntry]()
for (key,value) in surveyData{
let entry = PieChartDataEntry(value: Double(value), label: key)
data.append(entry)
}
let chart = PieChartDataSet(values: data, label: "")
chart.colors = ChartColorTemplates.material()
chart.sliceSpace = 2
chart.selectionShift = 5
chart.xValuePosition = .outsideSlice
chart.yValuePosition = .outsideSlice
chart.valueTextColor = .black
chart.valueLineWidth = 0.5
chart.valueLinePart1Length = 0.2
chart.valueLinePart2Length = 4
chart.drawValuesEnabled = true
let chartData = PieChartData(dataSet: chart)
pieView.data = chartData
}}`
Try this with your data set:
chart.selectionShift = 0