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 had create a bar chart which had the 9 categories label for the xAxis: ["Foods", "House Loan", "Insurance", "Petrol", "Saving", "Train", "Others", "Books & Magazine", "Car park"]
But in the charts it just show: Foods, Insurance, Saving, Others and Car park
Any one know how to solve it?
Here the source code for setting xAxis
public func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return self.categories[Int(value)]
}
func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [BarChartDataEntry] = []
for i in 0..<dataPoints.count {
let value = values[i] as Double
let dataEntry = BarChartDataEntry(x: Double(i), y:value)
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Total Amount")
var colors: [UIColor] = []
for _ in 0..<dataPoints.count {
let red = Double(arc4random_uniform(256))
let green = Double(arc4random_uniform(256))
let blue = Double(arc4random_uniform(256))
let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1)
colors.append(color)
}
chartDataSet.colors = colors
chartDataSet.colors = ChartColorTemplates.joyful()
barChartView.chartDescription?.text = ""
barChartView.xAxis.labelPosition = .bottom
barChartView.xAxis.drawGridLinesEnabled = false
barChartView.xAxis.granularityEnabled = true
barChartView.xAxis.granularity = 1.0
barChartView.xAxis.decimals = 0
let chartData = BarChartData()
chartData.addDataSet(chartDataSet)
barChartView.data = chartData
barChartView.xAxis.valueFormatter = self
let format = NumberFormatter()
format.numberStyle = .decimal
let formatter = DefaultValueFormatter(formatter: format)
chartData.setValueFormatter(formatter)
barChartView.animate(xAxisDuration: TimeInterval(1))
}
The text was updated successfully, but these errors were encountered:
I had create a bar chart which had the 9 categories label for the xAxis: ["Foods", "House Loan", "Insurance", "Petrol", "Saving", "Train", "Others", "Books & Magazine", "Car park"]
But in the charts it just show: Foods, Insurance, Saving, Others and Car park
Any one know how to solve it?
Here the source code for setting xAxis
The text was updated successfully, but these errors were encountered: