简体   繁体   中英

Highcharts y-axis tick interval

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.

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM