Code: Select all
import Highcharts
import SwiftUI
struct ContentView: View {
private var chartOptions: HIOptions {
let options = HIOptions()
let chart = HIChart()
options.chart = chart
let exporting = HIExporting()
exporting.enabled = true
let series = HISeries()
series.name = "Series 1"
series.data = [439, 525, 577, 696, 975, 119, 131, 151]
options.series = [series]
return options
}
var body: some View {
ChartView(options: chartOptions)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ChartView: UIViewControllerRepresentable {
var options: HIOptions
func makeUIViewController(context: Context) -> some UIViewController {
let viewController = UIViewController()
let chartView = HIChartView()
//chartView.plugins = ["exporting","export-data"]
chartView.viewController = viewController
viewController.view = chartView
return viewController
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
guard let chartView = uiViewController.view as? HIChartView else { return }
chartView.options = options
}
}