如何设置iOS雷达图的轴选项?

时间:2016-12-01 09:08:24

标签: ios swift ios-charts

我想用danielgindi绘制带有iOS图表库的雷达图表,但我无法弄清楚如何使用选项,尤其是关于轴的选项。

它通常可以正常工作,但是当我将变量列表(array)设置为[100.0, 100.0, 100.0, 100.0, 100.0]时,它会显示如下图所示:

相反,当我将array设置为[90.0, 80.0, 90.0, 70.0, 20.0]时,尽管我的代码仍然是网格线的间隔不是20:

从这些输出来看,问题的原因似乎是轴的选项。但是,我自己无法解决这个问题。
如何修复图表的大小和轴的范围,并根据需要绘制网格线?

我使用Xcode 8.1 / swift 2.3 / Charts 2.3.1。

import UIKit
import Charts

class ViewController: UIViewController {

@IBOutlet weak var radarChartView: RadarChartView!

//Label
let subjects = ["English", "Math", "Physics", "Chemistry", "Biology"]
//Points
let array = [100.0, 100.0, 100.0, 100.0, 100.0]

override func viewDidLoad() {
    super.viewDidLoad()
    setChart(subjects, values: array)
    print("array:")
    print(array)
}

func setChart(dataPoints: [String], values: [Double]) {

    radarChartView.noDataText = "You need to provide data for the chart."
    var dataEntries: [ChartDataEntry] = []
    for i in 0..<dataPoints.count {
        let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }
    let chartDataSet = RadarChartDataSet(yVals: dataEntries, label: "Units Sold")
    let chartData = RadarChartData(xVals: subjects, dataSet: chartDataSet)
    radarChartView.data = chartData

    //Options of radarChart
    radarChartView.sizeToFit()
    radarChartView.descriptionText = ""

    //Options for the axis from here. The range is 0-100, the interval is 20
    radarChartView.yAxis.labelCount = 6
    radarChartView.yAxis.axisMinValue = 0.0
    radarChartView.yAxis.axisMaxValue = 100.0

    radarChartView.rotationEnabled = false
    chartDataSet.drawFilledEnabled = true

    //Present the number as integer
    let numberFormatter = NSNumberFormatter()
    numberFormatter.generatesDecimalNumbers = false
    chartDataSet.valueFormatter = numberFormatter
    radarChartView.yAxis.valueFormatter = numberFormatter

    //Other options
    radarChartView.legend.enabled = false
    radarChartView.yAxis.gridAntialiasEnabled = true
    radarChartView.animate(yAxisDuration: 2.0)
}

1 个答案:

答案 0 :(得分:0)

我只需设置数据AFTER选项。 picture

$(function() {
    var array=[]; //disabled dates for the beforeShowDay go here

    $('input').datepicker({
      beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [$.inArray(string, array) == -1];
      }
    });

    $( "#date" ).datepicker({
      dateFormat: 'yy-mm-dd',
      minDate: new Date(),
      maxDate: '+1y',
      onSelect: function(date){

        var selectedDate = new Date(date);
        var msecsInADay = 86400000;
        var endDate = new Date(selectedDate.getTime() + msecsInADay);
        $("#date1").datepicker( "option", "minDate", endDate );
        $("#date1").datepicker( "option", "maxDate", '+1y' );
      }
    });

    $("#date1").datepicker({
      dateFormat: 'yy-mm-dd',
    });
  });