Shinobi Chart 初始数据缩小

Shinobi Chart initial data zoomed out

有没有办法为 shinobi charts 设置起始缩小值?

我已经尝试将 SChartDateRange(X 轴)的日期设置为开始日期,并将日期添加到结束日期,但没有解决。

提前致谢!

当前 Table 和轴设置

 //properties
@IBOutlet weak var chartView: UIView!
private var chart:ShinobiChart?
private let chartDataSource = LineGraphModDataSource()


//methods
override func viewDidLoad()
{
super.viewDidLoad()

chart = ShinobiChart(frame: chartView.bounds)
chartView.addSubview(chart!)

self.setupChart()

}//eom

func setupChart()
{
    chart?.delegate = self
    chart?.licenseKey =  Constants.shared.getLicenseKey()
    chart?.title             = "Chart #9"
    chart?.autoresizingMask  = [.flexibleHeight , .flexibleWidth]
    chart?.datasource = chartDataSource

/* X axis - Dates */
let dateRange:SChartDateRange = chartDataSource.getInititalDateRange()
chart?.xAxis = SChartDateTimeAxis()
chart?.xAxis.range = dateRange
chart?.xAxis.axisPosition = SChartAxisPositionNormal
chart?.xAxis.title = "Dates"
chart?.xAxis.labelFormatString = "MM dd yy"
chart?.xAxis.majorTickFrequency = SChartDateFrequency.dateFrequency(withDay: 3)
chart?.xAxis.minorTickFrequency = SChartDateFrequency.dateFrequency(withDay: 1)

//style
    //major
chart?.xAxis.style.majorGridLineStyle.showMajorGridLines = true
chart?.xAxis.style.majorTickStyle.showTicks = true
chart?.xAxis.style.majorTickStyle.showLabels = true

    //minor
chart?.xAxis.style.minorTickStyle.showTicks = true
chart?.xAxis.style.minorTickStyle.showLabels = true

//axis movement
chart?.xAxis.enableGesturePanning = true
chart?.xAxis.enableGestureZooming = true
chart?.xAxis.enableMomentumPanning = true
chart?.xAxis.enableMomentumZooming = true

/* Y axis - Values */
chart?.yAxis = SChartNumberAxis()
chart?.yAxis.defaultRange = SChartRange(minimum: 0, andMaximum: 10)
chart?.yAxis.title = "Y axis"
chart?.yAxis.axisPosition = SChartAxisPositionReverse
chart?.yAxis.majorTickFrequency = 1
chart?.yAxis.minorTickFrequency = 1
chart?.yAxis.rangePaddingLow = 0.5
chart?.yAxis.rangePaddingHigh = 0.5


//style
chart?.yAxis.style.majorGridLineStyle.showMajorGridLines = true
chart?.yAxis.style.majorTickStyle.showTicks = true
chart?.yAxis.style.majorTickStyle.showLabels = true
chart?.yAxis.style.minorTickStyle.showTicks = true
chart?.yAxis.style.minorTickStyle.showLabels = true

//axis movement
chart?.yAxis.enableGesturePanning = true
chart?.yAxis.enableGestureZooming = true
chart?.yAxis.enableMomentumPanning = true
chart?.yAxis.enableMomentumZooming = true

}//eom

当前起始图

所需的起始图

能够通过在创建图表时指定初始数据范围来实现这一点。

除了提供数据范围外,还必须扩大日期范围,以便图表在加载后看起来像是缩小了。

例如, 假设您的初始日期范围:

  • 2016 年 8 月 21 日
  • 8/25/16

范围内的第一个日期必须回滚 1 天,最后一天必须前移 1 天。所以范围将变为:

  • 2016 年 8 月 20 日
  • 8/26/16

    视图控制器

    SChartDateRange * startingDateRange = [self.datasource getInitialDateRange];
    self.chart.xAxis = [[SChartDateTimeAxis alloc] initWithRange:startingDateRange];
    self.chart.xAxis.majorTickFrequency = [[SChartDateFrequency alloc]initWithDay:1];
    

    数据源

    -(SChartDateRange *)getInitialDateRange {

     NSInteger lastIndex = [self.afterData count];
    lastIndex = lastIndex-1;
    
    NSDate * minDate = [self getDateFromIndex:0];
    NSDate * maxDate = [self getDateFromIndex:lastIndex];
    
    //expanding range by 1 day so its more visible on map
    NSInteger secondInDay = 86164;
    minDate = [minDate dateByAddingTimeInterval:-secondInDay];
    maxDate = [maxDate dateByAddingTimeInterval:secondInDay];
    
    SChartDateRange * range = [[SChartDateRange alloc]initWithDateMinimum:minDate andDateMaximum:maxDate];
    
    return range;
    

    }//eom