sandeepd
Posts: 19
Joined: Mon Oct 18, 2021 1:23 pm

Export Csv option

I am using Highchart on iOS app which is in swift. Would like to know if there is any example that can be referred to for having the option export as Csv?
andrzej.b
Site Moderator
Posts: 528
Joined: Mon Jul 15, 2024 12:34 pm

Re: Export Csv option

Hi,

You should be able to use exporting module as any other modules , and take advantage of the standard export module API.
You can check sample implementation of using extra module here: https://www.highcharts.com/demo/ios/heatmap

I hope you will find it useful.

Kind regards,
Andrzej
Highcharts Developer
sandeepd
Posts: 19
Joined: Mon Oct 18, 2021 1:23 pm

Re: Export Csv option

Though the example has export option in web but with the swift code in the URL doesn't have export option. Appreciate if you can point to exact example of how this can be used would be of appreciable.

Thank you.
andrzej.b
Site Moderator
Posts: 528
Joined: Mon Jul 15, 2024 12:34 pm

Re: Export Csv option

Hi,

Apologies for the longer time you had to wait.

In this code, thanks to using UIViewControllerRepresentable and exporting.enabled = true, the export button will work, but it will be a standard iOS share in the form of a photo:

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
  }

}
After uncommenting the line chartView.plugins = ["exporting","export-data"] and clicking the export button, a menu with the option to share PDF, CSV or Image will appear instead of the default iOS one.

Let me know if that is what you were looking for!

Kind regards,
Andrzej
Highcharts Developer

Return to “Highcharts Usage”