DDSpiderChart 0.5

DDSpiderChart 0.5

Deniz Adalar 维护。




  • Deniz Adalar

DDSpiderChart

CI Status Version License Platform

一个易于使用的 iOS 上的蜘蛛(雷达)图库,用 Swift 编写。

要求

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+
  • Swift 3.0+

安装

CocoaPods

DDSpiderChart 可通过 CocoaPods 访问。要安装它,只需在 Podfile 中添加以下行

pod "DDSpiderChart"

用法

用户界面构造器中的样式

您可以在用户界面构造器中使用DDSpiderChartView。只需拖放一个UIView并将其类设置为DDSpiderChartView。该库支持IBDesignable协议,因此在Xcode中您将看到您自定义的图表。

程序化方式

创建图表的新实例

let spiderChartView = DDSpiderChartView(frame: .zero) // Replace with some frame or add constraints
spiderChartView.axes = ["Axis 1", "Axis 2", "Axis 3", "Axis 4"] // Set axes by giving their labels
spiderChartView.addDataSet(values: [1.0, 0.5, 0.75, 0.6], color: .red) // Add first data set
spiderChartView.addDataSet(values: [0.9, 0.7, 0.75, 0.7], color: .blue) // Add second data set

从图表中移除数据集

let dataSet1 = spiderChartView.addDataSet(values: [0.9, 0.7, 0.75, 0.7], color: .blue) // Add second data set
// Later
spiderChartView.removeDataSetView(dataSet!)

自定义

spiderChartView.color = .white // This will change the color of the circles
spiderChartView.circleCount = 20 // How many circles there will be
spiderChartView.circleGap = 5 // The distance between circles
// circleCount * circleGap would be the radius of the chart itself

文本样式:(通过传递一个NSAttributedString数组作为坐标轴,它可以正常工作。这种方式提供了很大的灵活性。)

// Custom font with custom size & color example
func attributedAxisLabel(_ label: String) -> NSAttributedString {
  let attributedString = NSMutableAttributedString()
  attributedString.append(NSAttributedString(string: label, attributes: [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFont(name: "AvenirNextCondensed-Bold", size: 16)!]))
  return attributedString
}
    
override func viewDidLoad() {
  super.viewDidLoad()
  spiderChartView.axes = ["PAS", "DRI", "SPD", "DEF", "PHY", "SHT"].map { attributedAxisLabel($0) }
}

作者

Deniz Adalar, [email protected]

许可证

DDSpiderChart遵守MIT许可证。有关更多信息,请参阅LICENSE文件。