SWIFT – a combination chart using iOS-Charts (Line Map and Bar Chart)

I am trying to combine a line chart and bar chart in swift (iOS chart). Both the x-axis and y-axis seem to be scaled correctly, but the data is not displayed on the chart. I missed What’s up? enter image description here

import UIKit 
import Charts

class CombinedChartsTest: UIViewController {


@IBOutlet weak var combinedChart: CombinedChartView!


let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", " Dec"]
let unitsSold = [2.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 17.0, 2.0, 4.0, 5.0, 4.0]

override func viewDidLoad() {< br /> super.viewDidLoad()

setChart(months, yValuesLineChart: unitsSold, yValuesBarChart: unitsSold)
}

func setChart(xValues: [String], yValuesLineChart: [Double], yValuesBarChart: [Double]) {
combinedChart.noDataText = "Please provide data for the chart."

var yVals1: [ChartDataEntry] = [ChartDataEntry]()
var yVals2: [BarChartDataEntry] = [BarChartDataEntry]()

for i in 0..
yVals1.append(ChartDataEntry(value: yValuesLineChart[i], xIndex: i))
yVals2.append(BarChartDataEntry(value: yValuesBarChart[i]-1, xIndex: i ))

}

let lineChartSet = LineChartDataSet(yVals: yVals1, label: "Line Data")
let barChartSet: BarChartDataSet = BarChartDataSet(yVals: yVals2, label: "Bar Data")

let data: CombinedChartData = CombinedChartData(xVals: xValues, dataSets: [lineChartSet,barChartSet])

combinedChart.data = data

}
}

I finally found what was missing. < p>

import UIKit
import Charts

class CombinedChartsTest: UIViewController {


@ IBOutlet weak var combinedChartView: CombinedChartView!


let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" , "Aug", "Sep", "Oct", "Nov", "Dec"]
let unitsSold = [2.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 17 .0, 2.0, 4.0, 5.0, 4.0]

override func viewDidLoad() {
super.viewDidLoad()

setChart(months, yValuesLineChart: unitsSold, yValuesBarChart: unitsSold)
}

func setChart(xValues: [String], yValuesLineChart: [Double], yValuesBarChart: [Double]) {
combinedChartView.noDataText = "Please provide data for the chart."

var yVals1: [ChartDataEntry] = [ChartDataEntry]()
var yVals2: [BarChartDataEntry] = [BarChartDataEntry]()

for i in 0..
yVals1.append(ChartDataEntry(value: yValuesLineChart[i], xIndex: i))
yVals2.append(BarChartDataEntry(value: yValuesBarChart [i]-1, xIndex: i))

}

let lineChartSet = LineChartDataSet(yVals: yVals1, label: "Line Data")
let barChartSet : BarChartDataSet = BarChartDataSet(yVals: yVals2, label: "Bar Data")


let data: CombinedChartData = CombinedChartData(xVals: xValue s)
data.barData = BarChartData(xVals: xValues, dataSets: [barChartSet])
data.lineData = LineChartData(xVals: xValues, dataSets: [lineChartSet])

combinedChartView.data = data

}
}

I am trying to combine a line chart and bar in swift (iOS chart) Fig. Both the x-axis and y-axis seem to scale correctly, but the data is not displayed on the chart. What am I missing? enter image description here

import UIKit 
import Charts

class CombinedChartsTest: UIViewController {


@IBOutlet weak var combinedChart: CombinedChartView!


let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", " Dec"]
let unitsSold = [2.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 17.0, 2.0, 4.0, 5.0, 4.0]

override func viewDidLoad() {< br /> super.viewDidLoad()

setChart(months, yValuesLineChart: unitsSold, yValuesBarChart: unitsSold)
}

func setChart(xValues: [String], yValuesLineChart: [Double], yValuesBarChart: [Double]) {
combinedChart.noDataText = "Please provide data for the chart."

var yVals1: [ChartDataEntry] = [ChartDataEntry]()
var yVals2: [BarChartDataEntry] = [BarChartDataEntry]()

for i in 0..
yVals1.append(ChartDataEntry(value: yValuesLineChart[i], xIndex: i))
yVals2.append(BarChartDataEntry(value: yValuesBarChart[i]-1, xIndex: i) )

}

let lineChartSet = LineChartDataSet(yVals: yVals1, label: "Line Data")
let barChartSet: BarChartDataSet = BarChartDataSet(yVals: yVals2, label : "Bar Data")

let data: CombinedChartData = CombinedChartData(xVals: xValues, dataSets: [lineChartSet,barChartSet])

combinedChart.data = data

}
}

I finally found what was missing.

import UIKit
import Charts

class CombinedChartsTest: UIViewController {


@IBOutlet weak var combinedChartView: CombinedChartView!


let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let unitsSold = [2.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 17.0, 2.0, 4.0, 5.0, 4.0]

override func viewDid Load() {
super.viewDidLoad()

setChart(months, yValuesLineChart: unitsSold, yValuesBarChart: unitsSold)
}

func setChart(xValues : [String], yValuesLineChart: [Double], yValuesBarChart: [Double]) {
combinedChartView.noDataText = "Please provide data for the chart."

var yVals1: [ChartDataEntry] = [ChartDataEntry]()
var yVals2: [BarChartDataEntry] = [BarChartDataEntry]()

for i in 0..
yVals1. append(ChartDataEntry(value: yValuesLineChart[i], xIndex: i))
yVals2.append(BarChartDataEntry(value: yValuesBarChart[i]-1, xIndex: i))

}< br />
let lineChartSet = LineChartDataSet(yVals: yVals1, label: "Line Data")
let barChartSet: BarChartDataSet = BarChartDataSet(yVals: yVals2, label: "Bar Data")
< br />
let data: CombinedChartData = CombinedChartData(xVals: xValues)
data.barData = BarChartData(xVals: xValues, dataSets: [barChartSet])
data.lineData = LineChartData(xVals: xValues, dataSets: [lineChartSet])

combinedChartView.data = data

}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4108 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.