After upgrading to Swift 3, I started getting a BAD INSTRUCTION error every time I clicked a button that was supposed to open a new view controller, relating to the code that's in my ViewDidLoad. Here's the code in my ViewDidLoad:
if teacherModeVar == "Teacher" && password != "No password set" {
teacherModeRadioButton.state = NSOnState
singleUserRadioButton.state = NSOffState
unlockSettingsLabel.isEnabled = true
unlockSettingsTextBox.isEnabled = true
unlockSettingsButton.isEnabled = true
levelChoiceLabel.isEnabled = false
levelChoiceHelp.isEnabled = false
levelChoiceOption.isEnabled = false
teacherPasswordLabel.isEnabled = false
teacherPasswordHelp.isEnabled = false
enterNewPasswordLabel.isEnabled = false
enterNewPasswordBox.isEnabled = false
confirmPasswordLabel.isEnabled = false
confirmPasswordBox.isEnabled = false
saveNewPasswordButton.isEnabled = false
typeOfLearnerLabel.isEnabled = false
typeOfLearnerOption.isEnabled = false
} else {
teacherModeRadioButton.state = NSOnState
singleUserRadioButton.state = NSOffState
unlockSettingsLabel.isEnabled = false
unlockSettingsTextBox.isEnabled = false
unlockSettingsButton.isEnabled = false
levelChoiceLabel.isEnabled = true
levelChoiceHelp.isEnabled = true
levelChoiceOption.isEnabled = true
teacherPasswordLabel.isEnabled = true
teacherPasswordHelp.isEnabled = true
enterNewPasswordLabel.isEnabled = true
enterNewPasswordBox.isEnabled = true
confirmPasswordLabel.isEnabled = true
confirmPasswordBox.isEnabled = true
saveNewPasswordButton.isEnabled = true
typeOfLearnerLabel.isEnabled = false
typeOfLearnerOption.isEnabled = false
}
if teacherModeVar == "Single" {
singleUserRadioButton.state = NSOnState
teacherModeRadioButton.state = NSOffState
unlockSettingsLabel.isEnabled = false
unlockSettingsTextBox.isEnabled = false
unlockSettingsButton.isEnabled = false
levelChoiceLabel.isEnabled = false
levelChoiceHelp.isEnabled = false
levelChoiceOption.isEnabled = false
teacherPasswordLabel.isEnabled = false
teacherPasswordHelp.isEnabled = false
enterNewPasswordLabel.isEnabled = false
enterNewPasswordBox.isEnabled = false
confirmPasswordLabel.isEnabled = false
confirmPasswordBox.isEnabled = false
saveNewPasswordButton.isEnabled = false
typeOfLearnerLabel.isEnabled = true
typeOfLearnerOption.isEnabled = true
I'm basically using NSUserDefaults to populate the Preferences area correctly. It was working fine in Swift 2/Xcode 7, but after updating to Swift 3/Xcode 8 it gives me trouble. Any thoughts or ideas would be appreciated!
Related
I've created a simple small chart using (https://github.com/danielgindi/Charts), where i'm trying to remove everything beside the line itself, but i can't seem to remove the bottom zero axis. i've looked through the documentation, but cannot seem to remove it?
chart
class CellChartView: UIView {
var lineChart: LineChartView!
override init(frame: CGRect) {
super.init(frame: frame)
self.lineChart = LineChartView()
lineChart.backgroundColor = Color.lightTheme.value
lineChart.translatesAutoresizingMaskIntoConstraints = false
self.lineChart.chartDescription?.text = ""
self.lineChart.isUserInteractionEnabled = false
self.lineChart.legend.enabled = false
self.lineChart.minOffset = 0
self.lineChart.drawBordersEnabled = false
self.lineChart.drawGridBackgroundEnabled = false
self.lineChart.autoScaleMinMaxEnabled = true
self.lineChart.rightAxis.enabled = false
self.lineChart.leftAxis.enabled = false
self.lineChart.leftAxis.drawAxisLineEnabled = false
self.lineChart.leftAxis.axisLineColor = UIColor.green
self.lineChart.xAxis.drawLabelsEnabled = false
self.lineChart.xAxis.drawGridLinesEnabled = false
self.lineChart.xAxis.labelPosition = .bottom
self.lineChart.xAxis.drawLimitLinesBehindDataEnabled = false
self.lineChart.xAxis.enabled = false
self.lineChart.xAxis.axisLineColor = UIColor.clear
self.addSubview(self.lineChart)
lineChart.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
lineChart.topAnchor.constraint(equalTo: self.topAnchor, constant: -1).isActive = true
lineChart.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true
lineChart.heightAnchor.constraint(equalTo: self.heightAnchor).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setChartData(values: [Double], dates: [String]) {
var yValues : [ChartDataEntry] = [ChartDataEntry]()
for i in 0 ..< dates.count {
yValues.append(ChartDataEntry(x: Double(i + 1), y: values[i]))
}
let data = LineChartData()
let ds = LineChartDataSet(values: yValues, label: "Date")
ds.drawCirclesEnabled = false
ds.lineWidth = 1
ds.drawValuesEnabled = false
if (values.first ?? 0.0 > values.last ?? 0.0) {
ds.setColor(Color.redColor.value)
} else {
ds.setColor(Color.greenColor.value)
}
data.addDataSet(ds)
data.setDrawValues(false)
self.lineChart.data = data
}
}
If you just want to hide the xAxis, then I see two ways:
You could disable the xAxis xAxis.enabled = false
Or set the xAxis line color to transparent xAxis.axisLineColor = UIColor.clear
If you want to hide the horizontal and vertical lines being drawn through the center when you have disabled all grid lines and just want an X-Axis line as shown above in your drawing
lineChartDataSet.highlightColor = NSUIColor.clear
myLineChartView.xAxis.drawAxisLineEnabled = true
myLineChartView.xAxis.drawGridLinesEnabled = false
myLineChartView.xAxis.drawLabelsEnabled = false
myLineChartView.leftAxisAxis.drawAxisLineEnabled = false
This will just hide the horizontal and vertical lines while giving you the freedom to draw a line through X-Axis or Y-Axis.
If you just want to hide background gridlines
Just do
self.chartView?.leftAxis.drawGridLinesEnabled = false
self.charView?.xAxis.drawGridLinesEnabled = false
It will remove background grids for both axis. like that
I have the following line chart with 2 datasets.
One data set is dependent on the left yAxis the other one on the right yAxis.
Now i want them both to have the zero value in the same line.
The other values are ok to not be aligned.
How can i do that?
Code:
let speedLine = LineChartDataSet(values: speedEntries, label: "Speed")
speedLine.colors = [UIColor.white]
speedLine.drawCirclesEnabled = false
speedLine.axisDependency = .left
let powerLine = LineChartDataSet(values: powerEntries, label: "Power")
powerLine.colors = [UIColor.green]
powerLine.drawCirclesEnabled = false
powerLine.axisDependency = .right
let data = LineChartData()
data.addDataSet(speedLine)
data.addDataSet(powerLine)
chartView.data = data
chartView.xAxis.labelTextColor = UIColor.white
chartView.xAxis.labelCount = 20
chartView.leftAxis.labelTextColor = UIColor.white
chartView.rightAxis.labelTextColor = UIColor.green
chartView.legend.textColor = UIColor.white
chartView.rightAxis.axisMinimum = -80.0
chartView.chartDescription?.text = ""
Since you have:
chartView.rightAxis.axisMinimum = -80.0
You might need to do this as well:
chartView.leftAxis.axisMinimum = -80.0
I think there is still no resolution for this problem but we can still hide yAxis right side.
let yAxisLeft = chartView.leftAxis
yAxisLeft.drawGridLinesEnabled = true
yAxisLeft.gridColor = UIColor(hex: "DCE5EE")
yAxisLeft.labelFont = Theme.Font.main(ofSize: 9, weight: .regular)
yAxisLeft.labelXOffset = 2
yAxisLeft.labelTextColor = Theme.Color.white
yAxisLeft.axisLineColor = UIColor(hex: "DCE5EE")
yAxisLeft.drawAxisLineEnabled = false
yAxisLeft.labelCount = 4
yAxisLeft.axisMinLabels = 1
yAxisLeft.enabled = true
yAxisLeft.axisMinimum = 0
let yAxisRight = chartView.rightAxis
yAxisRight.drawGridLinesEnabled = false
yAxisRight.labelFont = Theme.Font.main(ofSize: 9, weight: .regular)
yAxisRight.labelXOffset = -2
yAxisRight.labelTextColor = Theme.Color.white
yAxisRight.drawAxisLineEnabled = false
yAxisRight.labelCount = 4
yAxisRight.axisMinLabels = 1
yAxisRight.enabled = true
yAxisRight.axisMinimum = 0
This is the final result:
I have a LineChartView and I want to show labels for the xAxis.
My code looks like this:
chartView.chartDescription?.enabled = false
chartView.drawGridBackgroundEnabled = false
chartView.dragEnabled = !chartView.isFullyZoomedOut
chartView.setScaleEnabled(true)
chartView.pinchZoomEnabled = true
chartView.setViewPortOffsets(left: 20.0, top: 0.0, right: 20.0, bottom: 0.0)
chartView.legend.enabled = true
chartView.legend.textColor = legendColor
chartView.legend.form = .empty
chartView.leftAxis.enabled = false
chartView.leftAxis.spaceTop = 0.4
chartView.leftAxis.spaceBottom = 0.4
chartView.rightAxis.enabled = false
chartView.xAxis.enabled = true
chartView.xAxis.labelTextColor = UIColor.black
chartView.xAxis.valueFormatter = self
chartView.xAxis.drawGridLinesEnabled = false
chartView.xAxis.drawLabelsEnabled = true
chartView.xAxis.drawAxisLineEnabled = false
chartView.highlightPerTapEnabled = false
chartView.highlightPerDragEnabled = false
if lineChartData.entryCount > 0 {
chartView.data = lineChartData
}
chartView.noDataText = NSLocalizedString("No chart data available", comment: String())
chartView.maxVisibleCount = 12
chartView.delegate = self
and
extension ChartCell: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return "foo"
}
}
In the debugger I see that stringForValue is being called, however in the drawn charts there are no labels.
I'm at a loss what I am missing here.
You have to set below :
chartView.xAxis.labelPosition = XAxis.LabelPosition.bottom
I have a generated chart. I'm trying to make it as simple as possible, thus removing all the unneeded lines, grids, labels etc. I can't get rid of the separator line between the bars and the top and right border lines, as you can see on the picture. I'm using HorizontalBarChart.
Also, here you can see my chart setup code, I tried to disable literally everything:
private func setupCharts(selectedHero: Int) {
classWinrateChart.descriptionText = ""
classWinrateChart.legend.enabled = false
classWinrateChart.drawBordersEnabled = false
classWinrateChart.drawMarkers = false
classWinrateChart.drawValueAboveBarEnabled = false
let chartDataSet = BarChartDataSet(yVals: dataSource, label: "Noaaah")
let chartData = BarChartData(xVals: ["", "", "", "", "", "", "", "", "", ""], dataSet: chartDataSet)
let color = constants.colors[selectedHero]
chartDataSet.colors = [color]
chartDataSet.valueFont = UIFont.systemFontOfSize(13)
//chartDataSet.drawValuesEnabled = false
let yAxis = classWinrateChart.leftAxis
let xAxis = classWinrateChart.rightAxis
yAxis.enabled = false
yAxis.drawLabelsEnabled = false
yAxis.drawAxisLineEnabled = false
yAxis.drawGridLinesEnabled = false
xAxis.enabled = false
xAxis.drawLabelsEnabled = false
xAxis.drawAxisLineEnabled = false
xAxis.drawGridLinesEnabled = false
classWinrateChart.rightAxis.enabled = false
yAxis.axisMaxValue = 100
yAxis.axisMinValue = 0
classWinrateChart.tintColor = colors[selectedHero]
classWinrateChart.drawGridBackgroundEnabled = false
classWinrateChart.data = chartData
}
This may help you :
var viwBar = BarChartView()
viwBar.leftAxis.drawGridLinesEnabled = false
viwBar.rightAxis.drawGridLinesEnabled = false
viwBar.xAxis.drawGridLinesEnabled = false
viwBar.drawGridBackgroundEnabled = false
//removes left and right axis representation
let yaxis = viwBar.getAxis(ChartYAxis.AxisDependency.Left)
yaxis.drawLabelsEnabled = false
yaxis.enabled = false
let xaxis = viwBar.getAxis(ChartYAxis.AxisDependency.Right)
xaxis.drawLabelsEnabled = false
xaxis.enabled = false
check your code, Is it like ?
let xAxis = classWinrateChart.rightAxis
classWinrateChart.rightAxis is rightAxis, not xAxis.
I updated ios-charts to the latest code after 2 months. I see lot of difference when I run the code.
This is before updating the library:
After updating:
Here's the code that generates the chart:
chart.infoTextColor = UIColor.blackColor()
chart.backgroundColor = UIColor.whiteColor()
chart.descriptionText = ""
chart.noDataText = "Loading..."
chart.rightAxis.enabled = false
chart.xAxis.wordWrapEnabled = true
chart.legend.position = .BelowChartCenter;
chart.legend.form = .Circle;
chart.legend.formSize = 10.0;
chart.legend.formToTextSpace = 10.0;
chart.legend.xEntrySpace = 4.0;
chart.legend.yEntrySpace = 2.0
chart.legend.stackSpace = 5.0
chart.legend.textColor = UIColor.blueColor()
chart.xAxis.gridColor = UIColor.blueColor()
// chart.xAxis.axisLineColor = UIColor.blueColor()
chart.gridBackgroundColor = UIColor.whiteColor()
chart.borderColor = UIColor.redColor()
// chart.xAxis.labelHeight = 18
// chart.xAxis.labelWidth = 18
chart.xAxis.labelPosition = .Bottom;
chart.xAxis.drawGridLinesEnabled = false;
chart.rightAxis.drawGridLinesEnabled = false;
//zooming..
chart.pinchZoomEnabled = false
chart.doubleTapToZoomEnabled = false
chart.scaleXEnabled = false
chart.scaleYEnabled = false
//new..
chart.leftAxis.labelPosition = .InsideChart
chartDataSet.barSpace = 0.38
Latest release has deprecated startAtZeroEnabled, which seems is your case.
Please try set customAxisMin to get the expcted range. e.g. customAxisMin = 0
remember to set it before calling chartView.data = yourData, or you need to specificly call chartView.notifyDataSetChanged()