简体   繁体   English

Highcharts y轴刻度间隔

[英]Highcharts y-axis tick interval

I am trying to create a combined graph using HighCharts in a swift iOS project.我正在尝试在 swift iOS 项目中使用 HighCharts 创建组合图。 The function for creating the graph is as follows.用于创建图形的 function 如下。

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]?如何根据数据[相反轴]在y2Axis中设置自动刻度间隔?
  • How to set the series data to the y2Axis?如何将系列数据设置为 y2Axis?

I tried to look for solution in highcharts documentation but I could not find any which will give me a solution.我试图在 highcharts 文档中寻找解决方案,但我找不到任何可以为我提供解决方案的解决方案。

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

How to set automatic tick intervals in y2Axis according to the data[Opposite axis]?如何根据数据[相反轴]在y2Axis中设置自动刻度间隔?

Remove tickPositions and use HIYAxis.linkedTo property.删除tickPositions并使用HIYAxis.linkedTo属性。

How to set the series data to the y2Axis?如何将系列数据设置为 y2Axis?

Use HISeries.yAxis property使用HISeries.yAxis属性


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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