You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use Horizontal Bar and the bars load fine. But don't load all variables name on the xAxis.
Display the variable in the Left of the Bar
This is my result:
This is the code:
var dataEntries: [BarChartDataEntry] = []
for i in 0..<barValues.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: barValues.object(at: i) as! Double)
dataEntries.append(dataEntry)
}
let barChartDataSet = BarChartDataSet(values: dataEntries, label: nil)
let barChartData = BarChartData(dataSet: barChartDataSet)
barChartData.setDrawValues(true)
cell.barChart.legend.enabled = false
cell.barChart.leftAxis.enabled = false
cell.barChart.rightAxis.enabled = false
cell.barChart.chartDescription?.enabled = false
cell.barChart.drawValueAboveBarEnabled = true
cell.barChart.leftAxis.axisMinimum = 0
cell.barChart.isUserInteractionEnabled = false
cell.barChart.noDataText = "NO DATA."
//Left Side
let xAxis = cell.barChart.xAxis
xAxis.enabled = true
xAxis.setLabelCount(barVariables.count, force: true)
xAxis.centerAxisLabelsEnabled = true
xAxis.drawLabelsEnabled = true
xAxis.drawGridLinesEnabled = false
xAxis.axisLineColor = UIColor.black
xAxis.labelPosition = .bottom
xAxis.labelFont = UIFont(name: "Avenir-Medium", size: 12.0)!
//Here I send Array<String> for change values Double to String, but don't load all values.
xAxis.valueFormatter = IndexAxisValueFormatter(values: arrayVariables)
//Current Values
let format = NumberFormatter()
format.numberStyle = NumberFormatter.Style.percent
format.maximumFractionDigits = 1
format.multiplier = 1.0
format.percentSymbol = " %"
let formatter = DefaultValueFormatter(formatter: format)
barChartData.setValueFormatter(formatter)
barChartData.setValueFont(UIFont(name: "Avenir-Light", size: 8.0))
barChartData.setValueTextColor(UIColor.black)
cell.barChart.data = barChartData
return cell
The text was updated successfully, but these errors were encountered:
jaragorns
changed the title
Display the variable in the Left of the Bar (iOS - Swift 3)
Display the variable String, not double value in the Left of the Bar (iOS - Swift 3)
Mar 3, 2017
jaragorns
changed the title
Display the variable String, not double value in the Left of the Bar (iOS - Swift 3)
Don't display or load all Variables on the Left of the Bar (iOS - Swift 3)
Mar 3, 2017
In all cases I need the value on _values, this method is called and return _values on position [index]
On First case need return _values[0] "Where index should be 0", and the index is -1. I forced to return _values[0] when index == -1
Original sentence if is return "" because: index != Int(value) many times.
open func stringForValue(_ value: Double,
axis: AxisBase?) -> String
{
let index = Int(value.rounded())
//--- 1. ---//
if index == -1 {
return _values[0]
}
//--- 2. ---//
//if index < 0 || index >= _valueCount || index != Int(value)
if index < 0 || index >= _valueCount
{
return ""
}
return _values[index]
}
I use Horizontal Bar and the bars load fine. But don't load all variables name on the xAxis.
Display the variable in the Left of the Bar
This is my result:
This is the code:
The text was updated successfully, but these errors were encountered: