I am using ios-charts to display a Horizontal BarChart with one value like this:
var dataEntries: [BarChartDataEntry] = []
let dataEntry = BarChartDataEntry(value: self.deductible!.deductiblePaid, xIndex: 0)
dataEntries.append(dataEntry)
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Deductible")
let chartData = BarChartData( xVals: dataPoints, dataSet: chartDataSet)
self.horizontalBarChart!.data = chartData
self.horizontalBarChart!.leftAxis.customAxisMax = 3000.0
self.horizontalBarChart!.leftAxis.startAtZeroEnabled = false
chartDataSet.colors = ChartColorTemplates.vordiplom()
I have tried to set the maximum value for the YAxis but its not effecting the graph. Edit: Please see the screenshot here : http://postimg.org/image/ogoj2t02f/ What I need is the bar should show the upper limit upto 3000 (or an amount specified dynamically) instead of the calculated upper limit.
I changed some code to make it, here is what I have currently:
self.horizontalBarChart!.noDataText = "You need to provide data for the chart."
self.horizontalBarChart!.setVisibleYRangeMaximum(3000, axis: ChartYAxis.AxisDependency.Left)
self.horizontalBarChart!.descriptionText = ""
var dataEntries: [BarChartDataEntry] = []
let dataEntry = BarChartDataEntry(value: self.deductible!.deductiblePaid, xIndex: 0)
dataEntries.append(dataEntry)
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: " ")
self.horizontalBarChart!.noDataText = "You need to provide data for the chart."
self.horizontalBarChart!.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0);
let chartData = BarChartData( xVals: dataPoints, dataSet: chartDataSet)
self.horizontalBarChart!.autoScaleMinMaxEnabled = false
self.horizontalBarChart!.data = chartData
self.horizontalBarChart!.leftAxis.axisMaximum = 1600
self.horizontalBarChart!.leftAxis.axisMinimum = 00
self.horizontalBarChart!.rightAxis.axisMaximum = 1600
//self.horizontalBarChart!.leftAxis.customAxisMax = 3000.0
//self.horizontalBarChart!.leftAxis.startAtZeroEnabled = false
chartDataSet.colors = ChartColorTemplates.vordiplom()
self.horizontalBarChart!.xAxis.labelPosition = .Top
self.horizontalBarChart!.backgroundColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1)
self.horizontalBarChart!.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
Please let me know if I am unclear and you need more details. This has been more challenging that I thought it would be! Any help here would be much appreciated.
Second Edit: I have the following code now :
func setHorizontalBarChartData() {
self.horizontalBarChart!.descriptionText = ""
var dataEntries: [BarChartDataEntry] = []
let dataEntry = BarChartDataEntry(value: 900, xIndex: 0)
dataEntries.append(dataEntry)
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: " ")
self.horizontalBarChart!.noDataText = "You need to provide data for the chart."
//self.horizontalBarChart!.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0);
let deductible = [" "]
let chartData = BarChartData( xVals: deductible, dataSet: chartDataSet)
self.horizontalBarChart!.data = chartData
self.horizontalBarChart!.leftAxis.startAtZeroEnabled = false
self.horizontalBarChart!.rightAxis.startAtZeroEnabled = false
self.horizontalBarChart!.rightAxis.customAxisMax = 3000
self.horizontalBarChart!.rightAxis.customAxisMin = 10
chartDataSet.colors = ChartColorTemplates.vordiplom()
self.horizontalBarChart!.xAxis.labelPosition = .Top
self.horizontalBarChart!.backgroundColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1)
self.horizontalBarChart!.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
}
I am still getting the same thing : http://postimg.org/image/ogoj2t02f/ What I need is only one bar with values upto 3000 and a bar chart coming upto 900. Could you please help ?