Reputation: 116
Implemented bar graph using core plot calling objective-c methods in Swift language,I am able plot the graph but bars have different width in size, first and last one are different and the middle one are same
@IBAction func onBarGraphBtnPressed(_ sender: Any) {
let a = chart!
a.graphType = kBar
a.clearData()
let symbol = LCPlotSymbol()
symbol.color = UIColor.yellow
let plot1 = LCPlot()
plot1.data = randomData(for: 3)
// plot1.lineColor = UIColor.yellow
plot1.fillColor = UIColor(red: 0.98, green: 0.59, blue: 0.07, alpha: 1.00)
a.add(plot1)
let ys: [LCAxisLabel] = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5].map {
let label = LCAxisLabel()
label.index = CGFloat($0)
label.text = "$\($0)k"
return label
}
chart.resetYAxisLabels(ys)
var index = 0
let xs: [LCAxisLabel] = ["Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov","Dec"].map {
let x = LCAxisLabel()
x.index = CGFloat(index)
x.text = $0
index = index + 1
return x
}
chart.resetXAxisLabels(xs)
chart.configureXAxisGridLine(nil)
//chart.configureYAxisGridLine(nil)
let gridLineStyle = LCLineStyle()
gridLineStyle.lineWidth = 0.3
gridLineStyle.lineColor = UIColor.gray
chart.configureYAxisGridLine(gridLineStyle)
chart.frame = self.view.bounds
chart.padding = 0
a.render()
}
Upvotes: 1
Views: 28