I am using the SwiftCharts library found here.
I have the following code:
class ChartTestViewController: UIViewController {
@IBOutlet weak var chartView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let xaxis = ["monday", "tuesday", "wednesday", "thursday", "friday"]
let yaxis = [1, 2, 3, 4, 5]
let letdoublearray = yaxis.map { Double($0) }
let tuples = zip(xaxis, letdoublearray).map { ($0, $1) }
let chartConfig = BarsChartConfig(
valsAxisConfig: ChartAxisConfig(from: 0, to: 8, by: 2)
)
let frame = CGRect(x: 0, y: 70, width: 300, height: 500)
let chart = BarsChart(
frame: frame,
chartConfig: chartConfig,
xTitle: "X axis",
yTitle: "Y axis",
bars: tuples,
color: UIColor.red,
barWidth: 20
)
self.chart = chart // error here
self.chartView = chart.view
I am getting an error at the self.chart = chart
line saying chart is not a member of the class. I already have chart
defined so I am not sure where else I need to create another chart variable.
Your view controller does not have a chart
property. Simply add one.
class ChartTestViewController: UIViewController {
var chart: BarsChart!
@IBOutlet weak var chartView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// lots of code here
self.chart = chart
}