0
votes

I am trying to create a combined graph using HighCharts in a swift iOS project. The function for creating the graph is as follows.

private func createBUGraph()
{
    let chartView = HIChartView(frame: self.chartHolderViewOutlet.bounds)
    

    let options = HIOptions()
    

    let title = HITitle()
    title.text = "UTS"
    options.title = title
    let subtitle = HISubtitle()
    subtitle.text = "Sales & Margin"
    options.subtitle = subtitle
    
    let xAxis = HIXAxis()
    xAxis.categories = ["A", "B", "C", "D"]//
    options.xAxis = [xAxis]

    let yAxis = HIYAxis()
    //yAxis.min = 0
    yAxis.title = HITitle()
    yAxis.title.text = "Sales"
    yAxis.lineWidth = 1
    

    let y2Axis = HIYAxis()
    y2Axis.title = HITitle()
    y2Axis.title.text = "Margin"
    y2Axis.lineWidth = 1
    y2Axis.tickPositions = [5,10,15,20]
    y2Axis.opposite = true
    options.yAxis = [yAxis,y2Axis]
    
    
    let Sales = HIColumn()
    Sales.name = "Sales"
    Sales.data = [3, 2, 1, 3]

    let SalesForecast = HIColumn()
    SalesForecast.name = "Sales Forecast"
    SalesForecast.data = 2, 3, 5, 7]
    
    let Margin = HISeries()
    Margin.name = "Margin"
    Margin.data = [2.5, 1.2, 8.5, 5.5]
    Margin.marker = HIMarker()
    Margin.marker.lineWidth = 2
    Margin.marker.symbol = "circle"
   
    
    let MarginForeast = HISeries()
    MarginForeast.name = "Margin Foreast"
    MarginForeast.data = [3, 2.67, 3, 6.33] //
    MarginForeast.marker = HIMarker()
    MarginForeast.marker.lineWidth = 2
    MarginForeast.marker.symbol = "circle"
    
    
    options.series = [Sales, SalesForecast, Margin, MarginForeast]

    chartView.options = options
    
    self.chartHolderViewOutlet.addSubview(chartView)
}

The graph is drawing but I am stuck at the following issues

  • How to set automatic tick intervals in y2Axis according to the data[Opposite axis]?
  • How to set the series data to the y2Axis?

I tried to look for solution in highcharts documentation but I could not find any which will give me a solution.

2

2 Answers

0
votes
  • Remove y2Axis.tickPositions = [5,10,15,20]
  • Set series.yAxis = 1 (API)
0
votes

How to set automatic tick intervals in y2Axis according to the data[Opposite axis]?

Remove tickPositions and use HIYAxis.linkedTo property.

How to set the series data to the y2Axis?

Use HISeries.yAxis property


API: https://api.highcharts.com/ios/highcharts/